WhatYouClickIsWhatYouGet

Userscript that removes all event listeners and replaces all data-outbound-url attrbutes from links

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name WhatYouClickIsWhatYouGet
// @namespace whatyouclickiswhatyouget
// @author elypter
// @match *://*/*
// @grant none
// @version     3
// @description Userscript that removes all event listeners and replaces all data-outbound-url attrbutes from links
// ==/UserScript==

//Do you hate it when you hover over a link and it looks completely normal
//but when you click on it it takes you somewhere else or redirects you over some logging page?
//this script gets rid of all that fuckery so that what you click is what you get.
//Userscript that removes all event listeners and replaces all data-outbound-url attrbutes from links
//License: GPL3

//this script isnt particularly lean on performance but nothing to worry about. it took over 100ms on my over 10 year old laptop

var remove_all_listeners=false;

var suffixes=["yahoo.com","duckduckgo.com"]; //list of domains where all listeners are removed

if(remove_all_listeners)for(var i = 0; i < suffixes.length; i++) {
    var suffix=suffixes[i];
    if (window.location.hostname.substr(-suffix.length) == suffix){
        //removing listeners by adding one and then stopping others from running with stopPropagation()
        window.addEventListener("click", function (event) {
            event.stopPropagation();
        }, true);
        window.addEventListener("contextmenu", function (event) {
            event.stopPropagation();
        }, true);
        window.addEventListener("mousedown", function (event) {
            event.stopPropagation();
        }, true);
        window.addEventListener("onmouseup", function (event) {
            event.stopPropagation();
        }, true);
    }
}

var as = document.getElementsByTagName('a');
var a, actual_url;
for(var i = 0; i < as.length; i++) {
    a = as[i];

    //replace the data-outbound-url with the actual shown in the statusbar
    if(ValidURL(a.getAttribute('data-href-url'))&&ValidURL(a.getAttribute('data-outbound-url'))){
        actual_url = a.getAttribute('data-href-url');
        if(actual_url&&a.hostname!=location.hostname) a.setAttribute('data-outbound-url', actual_url); //not sure if a.hostname picks the right one
    }
    if(ValidURL(a.getAttribute('href'))&&ValidURL(a.getAttribute('data-outbound-url'))){
        actual_url = a.getAttribute('href');
        if(actual_url&&a.hostname!=location.hostname) a.setAttribute('data-outbound-url', actual_url);
    }

    if (a.hostname!=location.hostname){
        //removing listeners by cloning the element. listeners are supposedly not cloned with this method
        aClone = a.cloneNode(true);
        a.parentNode.replaceChild(aClone, a);

        //removing listeners by adding one and then stopping others from running with stopPropagation()
        a.addEventListener("click", function (event) {
            event.stopPropagation();
        }, true);
        a.addEventListener("contextmenu", function (event) {
            event.stopPropagation();
        }, true);
        a.addEventListener("mousedown", function (event) {
            event.stopPropagation();
        }, true);
        a.addEventListener("onmouseup", function (event) {
            event.stopPropagation();
        }, true);
    }
}

function ValidURL(url){
    if (url) if(url.indexOf('https://') == 0 || url.indexOf('http://') == 0);
    else return false;
}