// ==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?://www\.amazon(\.com?)?\.[a-z]{2,3}/.*$/ // @include /^https?://www\.newegg\.c(om|a)/.*$/ // @include /^https?://[a-z]+\.ebay(\.com?)?\.[a-z]{2,3}/.*$/ // @include /^https?://www\.bing\.com/.*$/ // @include https://www.youtube.com/* // @include http://stat.dealtime.com/* // @exclude https://apis.google.com/* // @exclude https://www.google.com/recaptcha/api2/* // @version 2.3 // @license GPL version 3 or any later version; http://www.gnu.org/copyleft/gpl.html // @downloadURL none // ==/UserScript== var doc = document; var links = doc.links; var bing = /^https?:\/\/www\.bing\.com/; var ebay = /^https?:\/\/[a-z]+\.ebay(\.com?)?\.[a-z]{2,3}/; var amazon = /^https?:\/\/www\.amazon(\.com?)?\.[a-z]{2,3}\//; var newegg = /^http:\/\/www\.newegg\.c(om|a)/; var youtube = /^https?:\/\/www\.youtube\.com/; var google = /^https?:\/\/[a-z]*\.google(\.com?)?\.[a-z]{2,3}\//; var dealtime = /http:\/\/stat\.dealtime\.com\/DealFrame\/DealFrame\.cmp\?/; var utmParams = /([?&#]utm_[a-z]+=[^&#]*|&)/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 = /&(aqs|as_qdr|authuser|bav|bi[wh]|bs|bvm|cad|channel|complete|cp|s?client|dpr|es_sm|g(fe|ws)_rd|gpsrc|h[ls]|ie|n?um|btnG|o[eq]|pbx|p[fq]|rct|rlz|sa(fe)?|s?ei|site|source(id)?|spell|tab|tbas|tbo|usg|ved|xhr|gs_(l|r[ni]|mss|id))=[^&]*/g; // -------- Main -------- if (bing.test(doc.URL)) { var newUrl = cleanBingSearch(doc.URL); if (doc.URL.startsWith('http:')) location.href = newUrl; else cleanPageUrl(newUrl); cleanLinks('all'); } else if (google.test(doc.URL)) { if (doc.URL.includes('/url?')) location.replace(cleanGoogleRedirect(doc.URL)); else if (doc.URL.includes('/imgres?imgurl=')) location.replace(cleanGoogleImageRedirect(doc.URL)); else if (/\.[a-z]{2,3}\/[a-z]*[?#]/.test(doc.URL)) { cleanPageUrl(cleanGoogleSearch(doc.URL)); cleanLinks('google',true); googleInstant(); } } else if (youtube.test(doc.URL)) { if (doc.URL.includes('/watch/')) cleanPageUrl(cleanYoutubeVideo(doc.URL)); else if (doc.URL.includes('redirect?')) location.replace(cleanYoutubeRedirect(doc.URL)); cleanLinks('youtube'); } else if (ebay.test(doc.URL)) { if (doc.URL.includes('/itm/')) cleanPageUrl(cleanEbayItem(doc.URL)); else if (doc.URL.includes('/sch/')||doc.URL.includes('/dsc/')) cleanPageUrl(cleanEbaySearch(doc.URL)); cleanLinks('ebay'); } else if (amazon.test(doc.URL)) { if (doc.URL.includes('/dp/')) cleanPageUrl(cleanAmazonItemdp(doc.URL)); else if (doc.URL.includes('/gp/product')) cleanPageUrl(cleanAmazonItemgp(doc.URL)); cleanLinks('amazon'); } else if (newegg.test(doc.URL)) { if (doc.URL.includes('/Product/Product.aspx')) cleanPageUrl(cleanNeweggItem(doc.URL)); cleanLinks('newegg'); } else if (dealtime.test(doc.URL)) { location.replace(cleanDealtime(doc.URL)); } // -------- Front functions -------- function cleanPageUrl(newUrl) { if (newUrl != doc.URL) history.replaceState(null,null,newUrl); } function cleanLinks(site, remain=false) { new MutationObserver(function(_,self) { for (var i=0, l=doc.getElementsByTagName("a"); i