知乎免登录

知乎免登录脚本

  1. // ==UserScript==
  2. // @name 知乎免登录
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.9
  5. // @description 知乎免登录脚本
  6. // @author You
  7. // @match https://*.zhihu.com/*
  8. // @grant none
  9. // ==/UserScript==
  10.  
  11. (function () {
  12. // 若要开启实验性功能,请将下方 experimentalFunction = false 改成 experimentalFunction = true
  13. const experimentalFunction = false
  14.  
  15. "use strict";
  16. if (document.location.href.indexOf("/signin?") > -1) {
  17. window.location.href = "//zhihu.com/search?";
  18. }
  19.  
  20.  
  21. function htmlObservation(mutationList,observer){
  22. for(let mutation of mutationList){
  23. if('attributes' === mutation.type && 'style' === mutation.attributeName){
  24. if(document.documentElement.style.overflow !== 'auto'){
  25. document.documentElement.style.overflow = 'auto'
  26. }
  27. }
  28. }
  29. }
  30.  
  31. function bodyObservation(mutationList,observer){
  32. if(document.getElementsByClassName('signFlowModal')[0]){
  33. const model = document.getElementsByClassName('Modal-wrapper')[0]
  34. if(model){
  35. model.parentNode.removeChild(model)
  36. }
  37. }else{
  38. if(experimentalFunction && document.getElementsByClassName('Modal-backdrop')[0]){
  39. const backdrop = document.getElementsByClassName('Modal-backdrop')[0]
  40. if(!backdrop.getAttribute('clickedevent')){
  41. backdrop.onclick = function(e){
  42. const closebutton = backdrop.parentNode.getElementsByClassName('Modal-closeButton')[0]
  43. if(closebutton){
  44. closebutton.click()
  45. }
  46. }
  47. backdrop.setAttribute('clickedevent',true)
  48. }
  49. }
  50. }
  51. }
  52.  
  53. document.documentElement.style.overflow = 'auto'
  54. const htmlObserverConfig = {attributes:true}
  55. const htmlObserver = new MutationObserver(htmlObservation)
  56. htmlObserver.observe(document.documentElement,htmlObserverConfig)
  57.  
  58. const bodyObserverConfig = {childList:true,subtree:true}
  59. const bodyObserver = new MutationObserver(bodyObservation)
  60. bodyObserver.observe(document.body,bodyObserverConfig)
  61.  
  62. })();