禁用网页

禁止用户打开某些网页

当前为 2022-01-10 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Disable specific sites
  3. // @name:zh-CN 禁用网页
  4. // @name:zh-TW 禁用網頁
  5. // @namespace http://tampermonkey.net/
  6. // @version 0.2
  7. // @description A script to ban a user from opening some specific sites
  8. // @description:zh-CN 禁止用户打开某些网页
  9. // @description:zh-TW 禁止用戶打開某些網頁
  10. // @author You
  11. // @match *
  12. // @icon data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
  13. // @grant GM_registerMenuCommand
  14. // @grant GM_unregisterMenuCommand
  15. // @license MIT
  16. // @run-at document-start
  17. // ==/UserScript==
  18.  
  19. (function() {
  20. 'use strict';
  21.  
  22. var disableStatus = false
  23.  
  24. function init(){
  25. reloadDisableStatus()
  26. stopLoadingPageIfInDisableList()
  27. }
  28.  
  29. function showDisableGmBtns(){
  30. let menu = GM_registerMenuCommand("Disable This Site", ()=>{
  31. toggleDisableStatus()
  32. document.body.innerHTML = ""
  33. GM_unregisterMenuCommand(menu)
  34.  
  35. })
  36. }
  37.  
  38. function showEnableGmBtns(){
  39. let menu = GM_registerMenuCommand("Enable This Site", ()=>{
  40. toggleDisableStatus()
  41. GM_unregisterMenuCommand(menu)
  42. location.reload()
  43. })
  44. }
  45.  
  46. /* function isInDisableList(){
  47. return localStorage.DisableSpecificSites?true:false
  48. } */
  49.  
  50. function reloadDisableStatus(){
  51. disableStatus = localStorage.DisableSpecificSites=="true"?true:false
  52. }
  53.  
  54. function stopLoadingPageIfInDisableList(){
  55. if(disableStatus == true){
  56. //console.log(disableStatus)
  57. //showErrorPage()
  58. window.stop()
  59. showEnableGmBtns()
  60. }else {
  61. showDisableGmBtns()
  62. }
  63.  
  64. }
  65.  
  66. function toggleDisableStatus(){
  67. if(disableStatus){
  68. disableStatus = false
  69. localStorage.DisableSpecificSites = false
  70. showDisableGmBtns()
  71. }
  72. else{
  73. disableStatus = true
  74. localStorage.DisableSpecificSites = true
  75. showEnableGmBtns()
  76. }
  77. }
  78.  
  79. function showErrorPage(){
  80. const HTMLcode = `
  81. <div style="text-align: center; margin-top: 30%">
  82. <svg xmlns="http://www.w3.org/2000/svg" width="72" height="72" fill="currentColor" class="bi bi-slash-circle" viewBox="0 0 16 16">
  83. <path d="M8 15A7 7 0 1 1 8 1a7 7 0 0 1 0 14zm0 1A8 8 0 1 0 8 0a8 8 0 0 0 0 16z"/>
  84. <path d="M11.354 4.646a.5.5 0 0 0-.708 0l-6 6a.5.5 0 0 0 .708.708l6-6a.5.5 0 0 0 0-.708z"/>
  85. </svg>
  86. <div style='margin-top: 20px; font-size: 24px;font-family: system-ui,-apple-system,"Segoe UI",Roboto,"Helvetica Neue",Arial,"Noto Sans","Liberation Sans",sans-serif,"Apple Color Emoji","Segoe UI Emoji","Segoe UI Symbol","Noto Color Emoji"'>
  87. This Webpage is disabled.
  88. </div>
  89. </div>
  90. `
  91.  
  92. document.write(HTMLcode)
  93. }
  94.  
  95. init()
  96.  
  97.  
  98. })();