// ==UserScript== // @name Newegg cart to post converter for eggxpert.com // @namespace http://userscripts.org/users/62850 // @description Converts the cart in to postable html that has been patched for the forums // @include http://secure.newegg.com/Shopping/ShoppingCart.aspx* // @include http://secure.newegg.ca/Shopping/ShoppingCart.aspx* // @version 3.0 // @grant none // @downloadURL none // ==/UserScript== function addCommas(nStr){//http://www.mredkj.com/javascript/nfbasic.html nStr += ''; x = nStr.split('.'); x1 = x[0]; x2 = x.length > 1 ? '.' + x[1] : ''; var rgx = /(\d+)(\d{3})/; while (rgx.test(x1)) { x1 = x1.replace(rgx, '$1' + ',' + '$2'); } return x1 + x2; } function findEle(target,i,e){ if(i==9) return document.evaluate(target, e?e:document, null, i, null).singleNodeValue; else return document.evaluate(target, e?e:document, null, i, null); } function make(tag){ return document.createElement(tag); } function makeTXT(txt){ return document.createTextNode(txt); } function genDivBox(table){ var div=make('div'), child=make('div'); child2=make('a'); div.style.height=findEle('.//body/div[@id="container"]',9,false).offsetHeight+'px'; div.id="GM_alert"; child.addEventListener('click',function(){ document.body.removeChild(findEle('.//body/div[@id="GM_alert"]',9,false)); },false); child.textContent="X"; child.className="close"; child.title="Close"; div.appendChild(child); child=make('div'); child.appendChild(makeTXT('If you would like to readable HTML code, paste it in the ')); child2.href="http://tools.arantius.com/tabifier"; child2.textContent='Tabifier'; child2.target="_blank"; child.appendChild(child2); child.appendChild(makeTXT('.')); child.appendChild(make('br')); child2=make('input'); child2.setAttribute('readonly','readonly'); child2.setAttribute('onclick','this.select();'); child2.value=table.outerHTML; child.appendChild(child2); child.appendChild(makeTXT('Copy & Paste the above code.')); child.appendChild(make('br')); child2=make('fieldset'); child2.innerHTML='Preview'; child.appendChild(make('center')); child.childNodes[child.childNodes.length-1].appendChild(child2); div.appendChild(child); child2.appendChild(table); document.body.appendChild(div); } var holder=findEle('.//table[@class="head"]/tbody/tr[@class="tool-bar"]/td',6,false),btn,style; if(holder.snapshotLength==2){ btn=make('a'); btn.className='button button-mini button-tertiary'; btn.href="javascript:return false;"; btn.textContent='Generate HTML Code'; btn.title="HTML code for posting on forums"; btn.addEventListener('click',function(){ var table,tbody,tr,td,div,img, i,cart,item,val,a,txt,IMG, items=Array(),mir=Array(); table=make('table'); table.border=1; table.appendChild(make('tbody')); tbody=table.childNodes[0]; tr=make('tr'); tr.align="center"; td=make('th'); td.textContent='Item'; td.setAttribute('colspan',2); tr.appendChild(td); td=make('th'); td.textContent='Quantity'; tr.appendChild(td); td=make('th'); td.textContent='Price'; tr.appendChild(td); tbody.appendChild(tr); cart=findEle('.//table[@class="shipping-group"]/tbody/tr',6); for(i=0;i0){ td=make('td'); td.setAttribute('colspan',2); td.appendChild(makeTXT(mir.length>1?'There are '+mir.length+' Mail-in Rebates: ':'There is '+mir.length+' Mail-in Rebate: ')); for(i=0;i0?2:4); td.appendChild(a) tr.appendChild(td); tbody.appendChild(tr); genDivBox(table); },false); holder.snapshotItem(1).appendChild(btn); } style=make('style'); style.type="text/css"; style.textContent='\ #GM_alert{\ position:absolute;\ top:0;\ left:0;\ width:calc(100% - 60px);\ background-color:rgba(0,0,0,0.5);\ padding:30px;\ z-index:9001;\ }\ #GM_alert a{\ color:blue;\ }\ #GM_alert .close{\ background-color:red;\ width:24px;\ height:24px;\ position:absolute;\ right:3px;\ top:3px;\ border:1px solid white;\ color:white;\ border-radius:5px;\ font-family:monospace;\ font-size:21px;\ text-align:center;\ cursor:pointer;\ }\ #GM_alert > div:not(.close){\ border-radius:5px;\ background-color:#FFF;\ padding:10px;\ }\ #GM_alert fieldset{\ display:inline;\ border-radius:5px;\ text-align:left;\ }\ #GM_alert > div > input{\ width:calc(100% - 9px);\ }\ #GM_alert table{\ margin:0;\ }'; document.head.appendChild(style);