SwissCows Un-target Web Result Links to Open in Same Tab

Strip target="_blank" from results links (2020-07-23)

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name        SwissCows Un-target Web Result Links to Open in Same Tab
// @namespace   JeffersonScher
// @description Strip target="_blank" from results links (2020-07-23)
// @author      Jefferson "jscher2000" Scher
// @copyright   Copyright 2020 Jefferson Scher
// @license     BSD 3-clause
// @include     https://swisscows.com/*
// @version     0.5
// @grant       none
// ==/UserScript==

// Check element for targeted links (and remove target attribute)
function SCUtWRL_checkNode(el){
  var tgts = el.querySelectorAll('.web-results a[target="_blank"]');
  if (tgts.length > 0){
    for (var i=0; i<tgts.length; i++) tgts[i].removeAttribute("target");
  }
}
// Add MutationObserver to catch additions
var SCUtWRL_chgMon = new window.MutationObserver(function(mutationSet){
  mutationSet.forEach(function(mutation){
    for (var i=0; i<mutation.addedNodes.length; i++){
      if (mutation.addedNodes[i].nodeType == 1){
        SCUtWRL_checkNode(mutation.addedNodes[i]);
      }
    }
  });
});
// attach chgMon to document.body
var opts = {childList: true, subtree: true};
SCUtWRL_chgMon.observe(document.body, opts);
// Check initial results
SCUtWRL_checkNode(document.body);