-
-
Save ciknight/7aca1886c9ca77bfaa1f4afd99bb2164 to your computer and use it in GitHub Desktop.
Revisions
-
ambar revised this gist
Feb 3, 2017 . No changes.There are no files selected for viewing
-
ambar revised this gist
Sep 13, 2016 . No changes.There are no files selected for viewing
-
ambar revised this gist
Sep 13, 2016 . 1 changed file with 25 additions and 24 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,62 +1,63 @@ // ==UserScript== // @name nospm // @version 1.1 // @description 移除虾米、淘宝和天猫网址中的 spm 参数(包括地址栏和页面中的链接) // @include *://*.xiami.com/* // @include *://*.taobao.com/* // @include *://*.tmall.com/* // ==/UserScript== let forEach = Function.call.bind([].forEach) let removeSpm = (url, next) => { let search = url.search if (!search) return let query = parseQuery(search.slice(1)) if (query.spm) { delete query.spm let param = toParam(query) next(url.origin + url.pathname + (param ? '?' + param : '') + url.hash) } } let parseQuery = (param) => { return param.split('&') .map((pair) => pair.split('=')) .reduce((o, p) => { o[p[0]] = decodeURIComponent(p[1]); return o }, {}) } let toParam = (object) => { return Object.keys(object) .map((key) => key + '=' + encodeURIComponent(object[key])) .join('&') } let removeLinkSpm = (link) => { removeSpm(link, (newUrl) => { link.href = newUrl }) } let removeLocationSpm = () => { removeSpm(location, (newUrl) => { history.replaceState(null, document.title, newUrl) }) } let isLink = (node) => { return node && node.nodeName === 'A' } let observer = new MutationObserver((mutations) => { mutations.forEach((mutation) => { let type = mutation.type if (type === 'attributes') { if (mutation.attributeName === 'href' && isLink(mutation.target)) { removeLinkSpm(mutation.target) } } else if (type === 'childList' || type === 'subtree') { forEach(mutation.addedNodes, (node) => { if (isLink(node)) { removeLinkSpm(node) } @@ -65,6 +66,6 @@ var observer = new MutationObserver(function(mutations) { }) }) observer.observe(document.body, {attributes: true, childList: true, subtree: true}) forEach(document.links, removeLinkSpm) removeLocationSpm() -
ambar revised this gist
Apr 2, 2014 . 1 changed file with 3 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -16,14 +16,14 @@ var removeSpm = function(url, next) { if (query.spm) { delete query.spm var param = toParam(query) next(url.origin + url.pathname + (param ? '?' + param : '') + url.hash) } } var parseQuery = function(param) { return param.split('&') .map(function(pair) { return pair.split('=') }) .reduce(function(o, p) { o[p[0]] = decodeURIComponent(p[1]); return o }, {}) } var toParam = function(object) { -
ambar created this gist
Mar 22, 2014 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,70 @@ // ==UserScript== // @name nospm // @description 移除虾米、淘宝和天猫网址中的 spm 参数(包括地址栏和页面中的链接) // @include http://*.xiami.com/* // @include http://*.taobao.com/* // @include http://*.tmall.com/* // ==/UserScript== var each = [].forEach var removeSpm = function(url, next) { var search = url.search if (!search) return var query = parseQuery(search.slice(1)) if (query.spm) { delete query.spm var param = toParam(query) next('//' + url.host + url.pathname + (param ? '?' + param : '')) } } var parseQuery = function(param) { return param.split('&') .map(function(pair){ return pair.split('=') }) .reduce(function(o, p){ o[p[0]] = decodeURIComponent(p[1]); return o }, {}) } var toParam = function(object) { return Object.keys(object) .map(function(key) { return key + '=' + encodeURIComponent(object[key]) }) .join('&') } var removeLinkSpm = function(link) { removeSpm(link, function(newUrl) { link.href = newUrl }) } var removeLocationSpm = function() { removeSpm(location, function(newUrl) { history.replaceState(null, document.title, newUrl) }) } var isLink = function(node) { return node && node.nodeName === 'A' } var observer = new MutationObserver(function(mutations) { mutations.forEach(function(mutation) { var type = mutation.type if (type === 'attributes') { if (mutation.attributeName === 'href' && isLink(mutation.target)) { removeLinkSpm(mutation.target) } } else if (type === 'childList' || type === 'subtree') { each.call(mutation.addedNodes, function(node) { if (isLink(node)) { removeLinkSpm(node) } }) } }) }) observer.observe(document.body, { attributes: true, childList:true, subtree: true }) each.call(document.links, removeLinkSpm) removeLocationSpm()