Greasy Fork 还支持 简体中文。

MSN.com news - redirect to original site

Automatically redirect MSN news pages to the original source site.

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

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

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

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

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

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

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

Advertisement:

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

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

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

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

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

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

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

Advertisement:

// ==UserScript==
// @name         MSN.com news - redirect to original site
// @namespace    http://tampermonkey.net/
// @version      2025-05-14
// @description  Automatically redirect MSN news pages to the original source site.
// @author       Jamie Landeg-Jones
// @match        https://www.msn.com/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=msn.com
// @grant        none
// @license      MIT
// @run-at       document-start
// ==/UserScript==

// Props to the hints from this post: joeytwiddle@github - https://github.com/Tampermonkey/tampermonkey/issues/1279#issuecomment-875386821

// "run-at document-start" is needed for this to work with TamperMonkey on Firefox.
// Without this, the default is to wait until DOMContentLoaded, which as far as I
// can see, is later than "document-start" but still earlier than necessary, so I
// don't know why FireFox needs this. Thanks to reddit user "AchernarB" for this fix:
// https://old.reddit.com/r/duckduckgo/comments/17ym4q1/how_do_i_disable_the_msn_amp_redirects_for_news/mhh57w0/
// https://developer.mozilla.org/en-US/docs/Web/API/Document/DOMContentLoaded_event

(function() {
    'use strict';

    function redirect_to_article()
      {
        let numAttempts = 0;
        let doneit = 0;

        let tryNow = function()
          {
            let link_tags = document.getElementsByTagName ('link');

            for (let loop=0; loop < link_tags.length; loop++)
              {
                if (link_tags[loop].rel && link_tags[loop].rel == 'canonical')
                  {
                    const new_url = link_tags[loop].href;

                    doneit = 1;

                    if (new_url.match ("^https://(www\.)?msn.com/"))
                      console.info ('MSN Redirect: Ignoring redirect (same site): ' + new_url);
                     else
                      {
                        console.info ('MSN Redirect: Redirecting to ' + new_url);
                        window.location = new_url
                      }
                  }
              }

            if (!doneit)
              {
                if (numAttempts++ >= 20)
                  console.warn ('Giving up after 20 attempts. Could not find canonical link');
                 else
                  {
                    console.info ('MSN Redirect: Retrying, attempt ' + numAttempts.toString() + ' of 20.');
                    setTimeout (tryNow, 250 * Math.pow (1.1, numAttempts));
                  }
              }
          }
        tryNow();
      }

     // Run the filter when the page loads
    window.addEventListener ('load', redirect_to_article);
})();