Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name Twitter to XCancel Redirect
- // @description Redirects X/Twitter links to XCancel.
- // @version 0.99
- // @author AUGUSTUS
- // @grant none
- // @icon https://miro.medium.com/v2/resize:fit:737/1*8mpu6OwgGu_-NMNo-q5oFw.jpeg (embed)
- // ==/UserScript==
- const XCANCEL_URL = 'xcancel.com'
- const TWITTER_URL = 'x.com'
- function redirectToXCancel () {
- document.querySelectorAll('a[href*="'+ TWITTER_URL +'"]').forEach((element) => {
- element.href = element.href.replace(TWITTER_URL, XCANCEL_URL)
- element.textContent = element.textContent.replace(TWITTER_URL, XCANCEL_URL)
- })
- }
- (new MutationObserver((mutations) => {
- let runCheck = false
- for (let mutation of mutations) {
- if (mutation.addedNodes.length || mutation.attributeName === 'href') {
- runCheck = true
- break
- }
- }
- if (runCheck) {
- redirectToXCancel()
- }
- })).observe(document.querySelector('body'), {attributeFilter: ['href'], childList: true, subtree: true})
- redirectToXCancel()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement