Convert to old reddit links on GWASI

15/3/2021, 12:47:07 pm

目前為 2021-03-15 提交的版本,檢視 最新版本

// ==UserScript==
// @name        Convert to old reddit links on GWASI
// @namespace   Violentmonkey Scripts
// @match       https://gwasi.com/
// @grant       none
// @version     1.0
// @author      -
// @description 15/3/2021, 12:47:07 pm
// @esversion   6
// ==/UserScript==

console.log('Starting the script')



function changeLink(links){
  links.forEach(function(node) {
  const linkText = node.getAttribute('href')
  const oldLinkText = linkText.replace('//www.', '//old.')
  node.setAttribute('href', oldLinkText)
  node.setAttribute('target', '_blank')
})
}

function changeLinks() {
const cid = setInterval(() => {
  const links = document.querySelectorAll('a')
  if (links.length) {
    changeLink(links)
    clearInterval(cid)
  }
}, 500)
}

// Debounce
let id = null;

const debounce = (fn, delay) => (...args) => {
  if (id) {
    clearInterval(id)
  }
  id = setTimeout(() => fn.apply(args), delay)
}

const queryInput = document.querySelector('#query')

const debounced = debounce(changeLinks, 500)

queryInput.addEventListener('keypress', debounced)
changeLinks()
console.log('Done with running the script')

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址