├── Check.html ├── LICENSE ├── README.md └── pagevisibilityuserscript.js /Check.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Page Visibility Test 5 | 6 | 7 | 8 | 9 | 38 | 39 | 40 | 41 | 42 | 93 |
94 |

Page Visibility Test

95 |

96 | This checks both the page visibility API and the old blur/focus API. 97 |
98 | To prevent websites from knowing your visibility status, use 99 | IceWreck/Page-Visibility-User-Script 100 |

101 |

Anchit

102 |
103 |

Visibility Log:

104 |

105 |

108 |

109 |
110 | 111 | 112 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 Anchit Bajaj 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Page-Visibility-User-Script 2 | Prevent websites from knowing if you have opened a new tab/window or if you are using a different application, etc. This userscript blocks the page visibility API and to some extent the old blur/focus APIs. 3 | 4 | Example: Twitter stops playing videos as soon as you switch tabs. This userscript prevents that. 5 | 6 | ## Instructions 7 | * Install a userscript extension like Violent Monkey. 8 | * Open the extension settings, hit install from URL. 9 | * https://raw.githubusercontent.com/IceWreck/Page-Visibility-User-Script/master/pagevisibilityuserscript.js 10 | * Confirm Installation. 11 | -------------------------------------------------------------------------------- /pagevisibilityuserscript.js: -------------------------------------------------------------------------------- 1 | // ==UserScript== 2 | // @name PreventPageVisibility 3 | // @namespace https://github.com/IceWreck 4 | // @match *://*/* 5 | // @run-at document-start 6 | // @grant none 7 | // @version 1.1 8 | // @author IceWreck 9 | // @description Block websites from knowing if you switched tabs/windows 10 | 11 | // ==/UserScript== 12 | 13 | // This userscript blocks the page visibility API and to some extent the old blur/focus APIs. 14 | 15 | let events_to_block = [ 16 | "visibilitychange", 17 | "webkitvisibilitychange", 18 | "mozvisibilitychange", 19 | "hasFocus", 20 | "blur", 21 | "focus", 22 | "mouseleave" 23 | ] 24 | 25 | for (let event_name of events_to_block) { 26 | document.addEventListener(event_name, function (event) { 27 | event.preventDefault(); 28 | event.stopPropagation(); 29 | event.stopImmediatePropagation(); 30 | }, true); 31 | } 32 | 33 | for (let event_name of events_to_block) { 34 | window.addEventListener(event_name, function (event) { 35 | event.preventDefault(); 36 | event.stopPropagation(); 37 | event.stopImmediatePropagation(); 38 | }, true); 39 | } 40 | 41 | 42 | document.hasFocus = function () { return true; }; 43 | document.onvisibilitychange = null; 44 | Object.defineProperty(document, "visibilityState", { value: "visible" }); 45 | Object.defineProperty(document, "hidden", { value: false }); 46 | Object.defineProperty(document, "mozHidden", { value: false }); 47 | Object.defineProperty(document, "webkitHidden", { value: false }); 48 | Object.defineProperty(document, "webkitVisibilityState", { value: "visible" }); 49 | --------------------------------------------------------------------------------