阻止维基漫游

防止维基百科漫游。在尝试访问新页面时弹框报警,并阻止加载。离开漫游,拥抱效率!

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name        No Wiki Wandering
// @name:zh-CN  阻止维基漫游
// @namespace   hghwng
// @version     1
// @grant       none
// @include     *.wikipedia.org/wiki/*
// @description Prevent Wikipedia wandering. Show a dialog when you try to visit a new page, and the action is prevented. No wandering, more productivity!
// @description:zh-CN 防止维基百科漫游。在尝试访问新页面时弹框报警,并阻止加载。离开漫游,拥抱效率!
// ==/UserScript==

(function () {
  var startTime = Date.now();
  
  document.addEventListener('click', function (e) {
    var target = e.target;
    while (target) {
      if (target.tagName == 'A') break;
      target = target.parentNode;
    }
    if (target.tagName != 'A') return;
    
    var targetUrl = target.href;
    var currentUrl = window.location.origin + window.location.pathname;
    if (targetUrl.startsWith(currentUrl)) {
      if (targetUrl.length <= currentUrl.length) return;
      if (target.href[currentUrl.length] == '#') return;
    }
    
    var diff = (Date.now() - startTime) / 1000;
    alert("You have wasted " + diff.toFixed() + " seconds on Wikipedia!");
    e.preventDefault();
  })
})()