Disable specific sites

A script to prevent a user opening some specific sites

目前为 2022-01-09 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Disable specific sites
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.1
  5. // @description A script to prevent a user opening some specific sites
  6. // @author You
  7. // @match *
  8. // @icon data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
  9. // @grant GM_registerMenuCommand
  10. // @grant GM_unregisterMenuCommand
  11. // @license MIT
  12. // @run-at document-start
  13. // ==/UserScript==
  14.  
  15. (function() {
  16. 'use strict';
  17.  
  18. var disableStatus = false
  19.  
  20. function init(){
  21. reloadDisableStatus()
  22. stopLoadingPageIfInDisableList()
  23. }
  24.  
  25. function showDisableGmBtns(){
  26. let menu = GM_registerMenuCommand("Disable This Site", ()=>{
  27. toggleDisableStatus()
  28. document.body.innerHTML = ""
  29. GM_unregisterMenuCommand(menu)
  30.  
  31. })
  32. }
  33.  
  34. function showEnableGmBtns(){
  35. let menu = GM_registerMenuCommand("Enable This Site", ()=>{
  36. toggleDisableStatus()
  37. GM_unregisterMenuCommand(menu)
  38. location.reload()
  39. })
  40. }
  41.  
  42. /* function isInDisableList(){
  43. return localStorage.DisableSpecificSites?true:false
  44. } */
  45.  
  46. function reloadDisableStatus(){
  47. disableStatus = localStorage.DisableSpecificSites=="true"?true:false
  48. }
  49.  
  50. function stopLoadingPageIfInDisableList(){
  51. if(disableStatus == true){
  52. //console.log(disableStatus)
  53. //showErrorPage()
  54. window.stop()
  55. showEnableGmBtns()
  56. }else {
  57. showDisableGmBtns()
  58. }
  59.  
  60. }
  61.  
  62. function toggleDisableStatus(){
  63. if(disableStatus){
  64. disableStatus = false
  65. localStorage.DisableSpecificSites = false
  66. showDisableGmBtns()
  67. }
  68. else{
  69. disableStatus = true
  70. localStorage.DisableSpecificSites = true
  71. showEnableGmBtns()
  72. }
  73. }
  74.  
  75. function showErrorPage(){
  76. const HTMLcode = `
  77. <div style="text-align: center; margin-top: 30%">
  78. <svg xmlns="http://www.w3.org/2000/svg" width="72" height="72" fill="currentColor" class="bi bi-slash-circle" viewBox="0 0 16 16">
  79. <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"/>
  80. <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"/>
  81. </svg>
  82. <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"'>
  83. This Webpage is disabled.
  84. </div>
  85. </div>
  86. `
  87.  
  88. document.write(HTMLcode)
  89. }
  90.  
  91. init()
  92.  
  93.  
  94. })();