No Referrer

Disable HTTP referer by adding rel="noreferrer". This prevents the destination site from receiving what URL the user came from. Press Command + Shift + R to toggle Referrer Policy.

目前为 2023-06-01 提交的版本。查看 最新版本

// ==UserScript== 
// @name        No Referrer
// @description Disable HTTP referer by adding rel="noreferrer". This prevents the destination site from receiving what URL the user came from. Press Command + Shift + R to toggle Referrer Policy.
// @author      Schimon Jehudah, Adv.
// @namespace   i2p.schimon.noreferrer
// @homepageURL https://gf.qytechs.cn/en/scripts/465950-no-referrer
// @supportURL  https://gf.qytechs.cn/en/scripts/465950-no-referrer/feedback
// @copyright   2023, Schimon Jehudah (http://schimon.i2p)
// @license     MIT; https://opensource.org/licenses/MIT
// @exclude     devtools://*
// @match       *://*/*
// @version     23.06
// @run-at      document-end
// @icon        data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iNjRtbSIgaGVpZ2h0PSI2NG1tIiB2aWV3Qm94PSIwIDAgNjQgNjQiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+PHRleHQgeG1sOnNwYWNlPSJwcmVzZXJ2ZSIgc3R5bGU9ImZvbnQtd2VpZ2h0OjQwMDtmb250LXNpemU6MTkycHg7bGluZS1oZWlnaHQ6MDt0ZXh0LWluZGVudDowO3RleHQtYWxpZ246c3RhcnQ7dGV4dC1kZWNvcmF0aW9uLXN0eWxlOnNvbGlkO3RleHQtZGVjb3JhdGlvbi1jb2xvcjojMDAwO3dyaXRpbmctbW9kZTpsci10YjtkaXJlY3Rpb246bHRyO3RleHQtb3JpZW50YXRpb246bWl4ZWQ7ZG9taW5hbnQtYmFzZWxpbmU6YXV0bztiYXNlbGluZS1zaGlmdDpiYXNlbGluZTt0ZXh0LWFuY2hvcjpzdGFydDtzaGFwZS1wYWRkaW5nOjA7c2hhcGUtbWFyZ2luOjA7aW5saW5lLXNpemU6MDtvcGFjaXR5OjE7ZmlsbDojMDAwO2ZpbGwtb3BhY2l0eToxO3N0cm9rZS13aWR0aDoxLjI3OTgyO3N0cm9rZS1saW5lY2FwOmJ1dHQ7c3Ryb2tlLWxpbmVqb2luOm1pdGVyO3N0cm9rZS1taXRlcmxpbWl0OjQ7c3Ryb2tlLWRhc2hvZmZzZXQ6MDtzdHJva2Utb3BhY2l0eToxO3N0b3AtY29sb3I6IzAwMDtzdG9wLW9wYWNpdHk6MSIgeD0iMTcuMDA1MjQ1IiB5PSIzMS42NTg0MDUiIHRyYW5zZm9ybT0idHJhbnNsYXRlKC00LjQzNjg1NjQgNDAuODk0OTQpIHNjYWxlKC4yNjQ1OCkiPjx0c3BhbiB4PSIxNy4wMDUyNDUiIHk9IjMxLjY1ODQwNSIgc3R5bGU9ImZvbnQtc2l6ZToxOTJweCI+8J+kqzwvdHNwYW4+PC90ZXh0Pjwvc3ZnPgo=
// ==/UserScript==

/*

## 🔁 Disable HTTP referer (i.e. referrer)
### _Prevent sending HTTP "referer" requests to destination website._

This userscript adds `rel="noreferrer"` to every page link.

_"Links with `rel="noreferrer"` set do not send the request's "referrer" header. This prevents the destination site from seeing what URL the user came from."_

---

#### Recommended Userscripts

#### 🔗️ [Clean URL Improved](https://openuserjs.org/scripts/sjehuda/Clean_URL_Improved)
Remove needless parameters from a given URL and correct it to a cleaner one.

---

#### Please visit our counterparts

#### Web Extensions

#### [Auto Referer](https://github.com/garywill/autoReferer)
Browser addon. Control referer to protect privacy and not break web. The addon (maybe the only one?) that deals with browser's `document.referrer` bug.

#### [Referer Modifier](https://github.com/airtower-luna/referer-mod)
Referer Modifier is a Web Extension for Firefox to modify the Referer header in HTTP requests, and the Javascript `document.referrer` property to match.

#### [Smart Referer](https://gitlab.com/smart-referrer)
Automatically hide HTTP and JavaScript Referer for cross-domain requests.

#### [NoRef: Open without Referer](https://addons.mozilla.org/firefox/addon/noref-open-without-referer/)
Adds a context menu option to open a link in a new tab without sending the HTTP referer information. A bare-bones replacement for the legacy addon "No-Referer" by Dor. Simply copies the selected link and opens a new tab to the destination.

#### [Referer Control](https://addons.mozilla.org/firefox/addon/referercontrol/)
Control the HTTP Referer on a per-site basis.

#### [pximg referer fixer](https://github.com/maple3142/pximg-referer)
Add Referer headers when requesting i.pximg.net in order to get some pximg images displayed correctly.

---

#### Upcoming changes
 * ~~Add an event listener~~;
 * ~~Add hotkey to toggle referer~~;
 * Consideration http://microformats.org/wiki/rel-me;
 * Use `location.origin`, if at all possible. It might be useful;
 * Use `origin` for element `<link/>`;

---

### <!-- img src="https://raw.githubusercontent.com/KDE/falkon/master/logo.png" height="30" alt="Falkon" title="Download Falkon Browser"/ --> 🦅 Designed for <span style='color:MediumPurple'>[Falkon](https://www.falkon.org/) web browser</span>‬<!-- ![Falkon Web Browser](https://raw.githubusercontent.com/KDE/falkon/master/logo.png "Falkon Web Browser") -->

*/

var namespace = 'i2p-schimon-noreferrer';
document.addEventListener('keyup', hotkey, false);

function hotkey(e) {
  // set hotkey Ctrl + Shift + 5
  //if (e.ctrlKey && e.shiftKey && e.which == 53) {
  // set hotkey Ctrl + Shift + R
  if (e.metaKey && e.shiftKey && e.which == 82) {
    toggleNoReferrer();
  }
}

function toggleNoReferrer() {
  if (document.querySelector(namespace)) {
    appendNoReferrer();
    document.querySelector(namespace).remove();
  } else {
    removeNoReferrer();
    warningBar();
  }
}

function appendNoReferrer() {
  let elements = ['area', 'form'];
  for (let i = 0; i < elements.length; i++) {
    for (const element of document.querySelectorAll(elements[i])) {
      element.rel = 'noreferrer';
    }
  }
  for (const element of document.querySelectorAll('link')) {
    element.referrerPolicy = 'no-referrer';
  }
  for (let i = 0; i < elements.length; i++) {
    for (const element of document.querySelectorAll('a[href]')) {
      // TODO CSS Selector to select a[href] which does
      // not start with hash, instead of "if" statement
      if (!element.href.startsWith(element.baseURI + '#')) {
        element.rel = 'noreferrer';
      }
    }
  }
  
  // Event delegation works and requires JS enabled
  document.body.addEventListener ("click", function(e) {
    if (e.target && e.target.nodeName == "A" && e.target.href) {
      if (!e.target.href.startsWith(e.baseURI + '#') ||
          !document.querySelector(namespace)) { // TODO Test
        e.target.rel = 'noreferrer';
      }
    }
  });
}

function removeNoReferrer() {
  for (const element of document.querySelectorAll('[rel="noreferrer"]')) {
    element.removeAttribute('rel');
  }
  for (const element of document.querySelectorAll('[referrerpolicy="no-referrer"]')) {
    element.removeAttribute('referrerpolicy');
  }
}

function warningBar() {
  let bar = document.createElement(namespace);
  document.body.append(bar);
  bar.innerHTML = '<b>WARNING! Referrer Policy has been <u>temporarily</u> enabled;<!-- br --> Reload page or click <code style="color: navajowhite;background: black;border-radius: 1em;padding: 3px;font-family: monospace;font-size: smaller;">Command</code> + <code style="color: navajowhite;background: black;border-radius: 1em;padding: 3px;font-family: monospace;font-size: smaller;">Shift</code> + <code style="color: navajowhite;background: black;border-radius: 1em;padding: 3px;font-family: monospace;font-size: smaller;">R</code> to restore privacy mode. (i.e. no-referrer)</b>'; // 🫵
  bar.title = 'Click to reload';
  //bar.title = 'Restore privacy mode by 𝐂𝐨𝐦𝐦𝐚𝐧𝐝 + 𝐒𝐡𝐢𝐟𝐭 + 𝐑 or click this bar to reload page.';
  bar.id = namespace;
  bar.style.backgroundColor = 'indianred'; // #2c3e50 coral
  bar.style.color = 'white'; // #eee navajowhite
  bar.style.right = 0;
  bar.style.left = 0;
  bar.style.top = 0;
  bar.style.zIndex = 10000000000;
  bar.style.padding = '6px'; //13px //15px //11px //9px //3px //1px
  bar.style.position = 'fixed';
  bar.style.textAlign = 'center'; // justify
  bar.style.direction = 'ltr';
  // set bar behaviour
  bar.onclick = () => {
    bar.style.display = 'none';
    location.reload();
  };
}

(function appendNoReferrerToLink() {
  // Add element <link/> with rel="noreferrer".
  // Some consider <link rel="noreferrer"/> as invalid.
  let link = document.createElement('link');
  document.head.append(link);
  link.referrerPolicy = 'no-referrer';
  link.rel = 'noreferrer';
})();

appendNoReferrer();

QingJ © 2025

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