// ==UserScript== // @run-at document-start // @name General URL Cleaner // @namespace // @description Cleans URL's from various popular sites. Also, makes sure the sites are using HTTPS. // @include /^https?://[a-z]+\.google(\.com?)?\.[a-z]{2,3}/.*$/ // @include /^https?://[a-z]+\.ebay(\.com?)?\.[a-z]{2,3}/.*$/ // @include /^https?://www\.amazon(\.com?)?\.[a-z]{2,3}/.*$/ // @include /^https?://www\.newegg\.c(om|a)/.*$/ // @include /^https?://www\.bing\.com/.*$/ // @include https://www.youtube.com/* // @include http://stat.dealtime.com/* // @include http://www.imdb.com/* // @exclude https://apis.google.com/* // @exclude https://www.google.com/recaptcha/api2/* // @version 2.8.2 // @license GPL version 3 or any later version; http://www.gnu.org/copyleft/gpl.html // @downloadURL none // ==/UserScript== var doc = document; var loc=location; var numLinks = 0; var lhost = loc.host; var lpath = loc.pathname; var ebay = /^[a-z]+\.ebay\.com?(\.[a-z]{2,3})?$/; var amazon = /^www\.amazon\.com?(\.[a-z]{2,3})?$/; var google = /^[a-z]+\.google\.com?(\.[a-z]{2,3})?$/; var amazonParams = /&(url|ie|pf_rd_[a-z]|bbn|rw_html_to_wsrp|ref_)=[^&#]*/; var utmParams = /&utm_[a-z]+=[^&]*/g; var neweggParams = /&(cm_sp|icid)=[^&#]*/g; var bingParams = /&(go|qs|form|FORM|filt|pq|s[cpk]|qpvt|cvid)=[^&#]*/g; var youtubeParams = /&(feature|src_vid|annotation_id|[gh]l)=[^&#]*/g; var ebayParams = /&(_(o?sacat|odkw|from|trksid)|rt)=[^&#]*/g; var googleParams = /&(sa(fe)?|ved|source(id)?|s?ei|tab|tbo|h[ls]|authuser|n?um|ie|aqs|as_qdr|bav|bi[wh]|bs|bvm|cad|channel|complete|cp|s?client|dpr|e(ch|msg|s_sm)|g(fe|ws)_rd|gpsrc|noj|btnG|o[eq]|p(si|bx|f|q)|rct|rlz|site|spell|tbas|usg|xhr|gs_[a-z]+)=[^&#]*/g; // -------- Main -------- if (lhost=='www.bing.com') { var newUrl = cleanBing(doc.URL); if (loc.protocol=='http:') loc.replace(newUrl); else cleanPageUrl(newUrl); cleanLinks('all'); } else if (lhost=='www.youtube.com') { if (lpath=='/watch') cleanPageUrl(cleanYoutube(doc.URL)); else if (lpath=='/redirect') loc.replace(cleanYoutubeRedir(loc.search)); cleanLinks('youtube'); } else if (lhost.endsWith('.newegg.com')||lhost.endsWith('.newegg.ca')) { if (loc.search) cleanPageUrl(cleanNewegg(doc.URL)); cleanLinks('newegg',1); } else if (lhost=='www.imdb.com') { if (loc.search) cleanPageUrl(cleanImdb(doc.URL)); cleanLinks('imdb'); deleteHash(); } else if (google.test(lhost)) { if (lpath=='/url'||lpath=='/imgres') loc.replace(cleanGoogleRedir(loc.search)); else if (loc.search||loc.hash.match(/[&#]q=/)) { cleanPageUrl(cleanGoogle(doc.URL)); cleanLinks('google',1); googleInstant(); } } else if (ebay.test(lhost)) { if (lpath.includes('/itm/')) cleanPageUrl(cleanEbayItem(loc)); else if (loc.search) cleanPageUrl(cleanEbayParams(doc.URL)); cleanLinks('ebay'); deleteHash(); } else if (amazon.test(lhost)) { if (lpath.includes('/dp/')) cleanPageUrl(cleanAmazonItemdp(loc)); else if (lpath.includes('/gp/product')) cleanPageUrl(cleanAmazonItemgp(loc)); else if (loc.search) cleanPageUrl(cleanAmazonParams(doc.URL)); cleanLinks('amazon'); deleteHash(); } // -------- Front functions -------- function cleanPageUrl(newUrl) { if (newUrl != doc.URL) history.replaceState(null,null,newUrl); } function cleanLinks(site, remain=0) { new MutationObserver(function(_,self) { links = doc.getElementsByTagName("a"); if (links.length>numLinks) { numLinks=links.length; console.time('clean'); for (var i=numLinks;0