知乎免登录

知乎免登录脚本

< Feedback on 知乎免登录

Review: Good - script works

§
Posted: 2020-12-01
Edited: 2020-12-01

貌似是加载需要时间,我只会这么改~

(function () {
"use strict";
if (document.location.href.indexOf("/signin?") > -1) {
window.location.href = "//zhihu.com/search?";
}

document.body.addEventListener("DOMNodeInserted", function (e) {
const model = e.target.getElementsByClassName("signFlowModal")[0];
if (model) {
const wrap = document.getElementsByClassName('Modal-wrapper')[0]
wrap.parentNode.removeChild(wrap);
setTimeout(slid,50); //延迟调用
}
});
})();
// 以下为添加部分
function slid(){
document.getElementsByTagName("html")[0].style.overflow = "auto";
}

manakanemuAuthor
§
Posted: 2020-12-01

请问为什么要延迟添加style? 我看到有其他人反应现在的脚本也会出现无法滚动的情况,但是在我这里换了好几台电脑也无法复现,你是观察到了什么现象吗?

§
Posted: 2020-12-01

可能是 React 会懒加载或者复用其他同类 Component,具体原因我没有分析。但是有一个可以复现的方法,右键选中一个知乎的链接,在后台打开这个页面,Chrome 会对后台的标签页限制 setTimeout 的触发频率,一般为 1 秒间隔,这个可能是一个问题。

https://greasyfork.org/zh-CN/scripts/417220-%E7%9F%A5%E4%B9%8E%E5%8E%BB%E9%99%A4%E5%BC%BA%E5%88%B6%E7%99%BB%E5%BD%95%E5%BC%B9%E5%87%BA%E6%A1%86/code

可以参考一下我改的,我自己用没有遇到什么问题。

manakanemuAuthor
§
Posted: 2020-12-01

确实,后台打开网页有几率可以复现这个问题。我试了几遍代码注入的顺序和知乎修改overflow的顺序不固定,应该是你说的,chrome后台处理的一些行为影响了脚本的注入顺序。现在代码已经改成用mutation observer 监控页面变化,目前还没有遇到问题。

§
Posted: 2020-12-01

就是无法滚动的问题,现在入了个门,请问像 “React 会懒加载或者复用其他同类 Component” “mutation observer” 这些东西需要学什么呀?

manakanemuAuthor
§
Posted: 2020-12-02

react这种属于前端框架,深入学vue、react这种框架的时候可以学到。学es678特性的时候也可能会涉及一些。mutation observer属于api的内容,api方面的问题去mdn搜就可以了。

§
Posted: 2020-12-03

好的谢谢

Post reply

Sign in to post a reply.