问一下朋友们,有木有过这种情况,你给你的朋友分享你在逛的淘宝产品的时候,你会发现链接是那样的冗长,是不是想把这个链接捏洗一下,今天这篇文章就告诉你怎么净化这些链接
前言
这里可能有人不太明白什么意思,其实这个是有一点处女座才会需要的功能,
看看这个链接:https://item.taobao.com/item.htm?spm=a1z10.1-c.w5003-16445064199.3.uAvJEE&id=520979027120&scene=taobao_shop
是不是炒鸡长啊,看着不干净是吧,其实真正的链接是这个:https://item.taobao.com/item.htm?id=520979027120
比较下是不是突然感觉整个世界都干劲了很多,今天云落介绍两种好用的办法。
看看这个链接:https://item.taobao.com/item.htm?spm=a1z10.1-c.w5003-16445064199.3.uAvJEE&id=520979027120&scene=taobao_shop
是不是炒鸡长啊,看着不干净是吧,其实真正的链接是这个:https://item.taobao.com/item.htm?id=520979027120
比较下是不是突然感觉整个世界都干劲了很多,今天云落介绍两种好用的办法。
小书签方法
首先看下代码
javascript: (function () { function getQueryString(name) { var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i"); var r = window.location.search.substr(1).match(reg); if (r != null) return r[2]; return null; } var site = window.location.href.match(/^http(s)?:\/\/[^?]*/); var id = getQueryString("id"); var q = getQueryString("q"); if (id != null) { var pureUrl = site[0] + "?id=" + id; } else if (q != null) { var pureUrl = site[0] + "?q=" + q; } else if (site[0].substr(site[0].length - 13) == "view_shop.htm") { var pureUrl = window.location.protocol + "//" + window.location.host; } else { var pureUrl = site[0]; } /* Apple Store 将国家设置为中国 Start */ pureUrl = pureUrl.replace(/^http(s)?:\/\/itunes\.apple\.com\/(\w{2}\/)?/,"https://itunes.apple.com/cn/"); /* Apple Store 将国家设置为中国 End */ var reload = prompt("净化后的网址是:",pureUrl); if(reload != null){ window.location.href = pureUrl; } })();
压缩下就是这样的
javascript: (function () { function getQueryString(name) { var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i"); var r = window.location.search.substr(1).match(reg); if (r != null) return r[2]; return null; } var site = window.location.href.match(/^http(s)?:\/\/[^?]*/); var id = getQueryString("id"); var q = getQueryString("q"); if (id != null) { var pureUrl = site[0] + "?id=" + id; } else if (q != null) { var pureUrl = site[0] + "?q=" + q; } else if (site[0].substr(site[0].length - 13) == "view_shop.htm") { var pureUrl = window.location.protocol + "//" + window.location.host; } else { var pureUrl = site[0]; } /* Apple Store 将国家设置为中国 Start */ pureUrl = pureUrl.replace(/^http(s)?:\/\/itunes\.apple\.com\/(\w{2}\/)?/,"https://itunes.apple.com/cn/"); /* Apple Store 将国家设置为中国 End */ var reload = prompt("净化后的网址是:",pureUrl); if(reload != null){ window.location.href = pureUrl; } })();
至于小书签的使用,如果你不太懂的话,可以看看云落以前写的文章→小书签使用方法
实际效果
浏览器脚本方法
浏览器脚本方法其实和小书签方法差不多,只是小书签方法是需要自己手动点击,而浏览器脚本是在指定页面自动生效,不需要人工干预。火狐浏览器以及类Chrome浏览器都可以利用扩展实现浏览器脚本功能,火狐浏览器使用的是GM脚本,类Chrome浏览器使用的是TM扩展,如果使用浏览器脚本可以看看这里→https://greasyfork.org/zh-CN
脚本代码
// ==UserScript== // @name taobao_fixed // @namespace tbpu // @include http://detail.tmall.com/* // @include https://detail.tmall.com/* // @include *.taobao.com/* // @version 1.4 // @description 淘宝天猫网址清理 // ==/UserScript== String.prototype.repeat = function(n) { return Array(n + 1).join(this); }; String.prototype.downcase = function() { return this.toLowerCase(); }; String.prototype.upcase = function() { return this.toUpperCase(); }; String.prototype.find = function(str) { return this.indexOf(str); }; String.prototype.has = function(str) { return (this.indexOf(str)) >= 0; }; var sPageUrl = window.location.href; if( sPageUrl.has('item.taobao.com') || sPageUrl.has('detail.tmall.com') ) { var q = sPageUrl.match(/id=(\d+)/) if( q.length > 0 ){ history.replaceState(null, null, 'item.htm?id='+q[1] ); } }else if ( sPageUrl.has('s.taobao.com') ){ var query = ''; if( sPageUrl.has('q=') ) { var q = sPageUrl.match(/q=[^&(!#)]+/); query += '?' + q[0]; } if( sPageUrl.has('cat=') ){ var q = sPageUrl.match(/cat=[\d+]+/); query += '&' + q[0]; } if( sPageUrl.has('sort=') ){ var q = sPageUrl.match(/sort=[^&]+/); query += '&' + q[0]; } if( sPageUrl.has('tab=') ){ var q = sPageUrl.match(/tab=(all|mall|old)/); if(q[0] !=='tab=all') { query += '&' + q[0]; } } if( sPageUrl.has('s=') ) { var q = sPageUrl.match(/s=(\d+)+/); query += '&' + q[0]; } if( query != '' ){ history.replaceState(null, null, 'search'+query); } } document.getElementById('page').addEventListener("DOMNodeInserted", function (e) { if( e.target.className == 'tb-content' ){ var elements = e.target.querySelectorAll('img'); //[data-ks-lazyload] for (var i = 0; i < elements.length; i++) { elements[i].src = elements[i].getAttribute('data-ks-lazyload'); elements[i].removeAttribute('data-ks-lazyload'); } } }, true);
OVER
-- 完 --
签到成功!签到时间:2017-05-26 18:53:45,每日打卡,生活更精彩哦~
尽然发文章了。。
云落大神冒泡了,快来围观!
不错的