Strips tracking and redirection from Yahoo search urls
当前为
// ==UserScript==
// @name Yahoo direct non-tracking search
// @description Strips tracking and redirection from Yahoo search urls
// @include https://*yahoo.com/*
// @version 1.0.2
// @author wOxxOm
// @namespace wOxxOm.scripts
// @license MIT License
// @grant none
// @run-at document-start
// ==/UserScript==
setMutationHandler(document, '.search-assist-form-wrapper form, a', function(observer, nodes) {
Array.prototype.forEach.call(nodes, function(node) {
switch (node.localName) {
case 'form':
if (node.action.indexOf('/search') > 0) {
node.addEventListener('submit', function(e){
e.preventDefault();
e.stopPropagation();
e.target.action = e.target.action.replace(/_yl[tu]=[\w;_=.-]+/, '');
e.target.submit();
});
}
break;
case 'a':
node.href = node.href.replace(/;?_yl[tu]=[\w;_=.-]+\/?/, '')
.replace(/^.+?\/RU=(http[^\/]+)\/?.*$/, function(s, url) { return decodeURIComponent(url) });
break;
}
});
return true;
});
function setMutationHandler(baseNode, selector, cb) {
var ob = new MutationObserver(function(mutations){
for (var i=0, ml=mutations.length, m; (i<ml) && (m=mutations[i]); i++)
for (var j=0, nodes=m.addedNodes, nl=nodes.length, n; (j<nl) && (n=nodes[j]); j++)
if (n.nodeType == 1)
if ((n = n.matches(selector) ? [n] : n.querySelectorAll(selector)) && n.length)
if (!cb(ob, n))
return;
});
ob.observe(baseNode, {subtree:true, childList:true});
}