marqqer 发表于 2021-8-28 18:57:10

网站定义了一个history()函数,导致脚本中无法访问Window.histor...

本帖最后由 marqqer 于 2021-8-28 18:58 编辑

请教一个问题:
网站定义了一个history()函数,导致脚本中无法访问Window.history对象,这种情况该怎么处理?
观察发现以下代码unsafeWindow.history获取的是网站自定义的history()函数,导致后续pushState无法执行,如果通过uBlock origin阻止加载相关的script文件,就可以正常工作try {
    unsafeWindow.history.pushState(null, curTitle, url);
} catch (e) {
    console.error('添加下一页到历史记录失败', e);
}想问问这种情况该怎么处理,如何才能正确的获取对History对象的引用?
相关资源:
脚本:https://greasyfork.org/zh-CN/scripts/292-my-novel-reader
网站:https://www.qianbitxt.com/book/2206/227873.html

陈公子的话 发表于 2021-8-28 19:13:29

等大佬

李恒道 发表于 2021-8-28 20:13:16

可以试试runat提前注入,对history搞个双向数据劫持
然后进行判断

李恒道 发表于 2021-8-28 20:19:43

// ==UserScript==
// @name         New Userscript
// @namespace    http://tampermonkey.net/
// @version      0.1
// @descriptiontry to take over the world!
// @author       You
// @match      https://www.qianbitxt.com/book/2206/227873.html
// @icon         https://www.google.com/s2/favicons?domain=qianbitxt.com
// @grant      none
// @run-at       document-start
// ==/UserScript==
window.newhistory=window.history

李恒道 发表于 2021-8-28 20:20:18

哥哥可以论坛也发点小脚本!

脚本体验师001 发表于 2021-8-28 20:31:10

发现在window里也有history
似乎这个才是正确的 window.history

marqqer 发表于 2021-8-28 21:08:24

李恒道 发表于 2021-8-28 20:19
// ==UserScript==
// @name         New Userscript
// @namespace    http://tampermonkey.net/


my-novel-reader这个脚本必须 // @run-at document-end ,试了"run-at document-start"无法工作,如果新开一个"run-at document-start"脚本, 可以成功添加window.newhistory=window.history,但在my-novel-reader里发现window没有 newhistory这个属性了,
"对history搞个双向数据劫持'具体怎么搞呢?
感谢回复!!

marqqer 发表于 2021-8-28 21:09:57

本帖最后由 marqqer 于 2021-8-28 21:11 编辑

脚本体验师001 发表于 2021-8-28 20:31
发现在window里也有history
似乎这个才是正确的 window.history谢谢,
我这window是undefined,怎么引用使用window?有什么特殊技巧吗,我用的Chrome浏览器

marqqer 发表于 2021-8-28 21:14:20

李恒道 发表于 2021-8-28 20:19
// ==UserScript==
// @name         New Userscript
// @namespace    http://tampermonkey.net/


有什么办法让脚本"document-start"执行一部分, "document-end"执行一部分?

李恒道 发表于 2021-8-28 21:18:04

marqqer 发表于 2021-8-28 21:08
my-novel-reader这个脚本必须 // @run-at document-end ,试了"run-at document-start"无法工作,如果新开 ...

对history搞个双向数据劫持是我脑子出错了
如果就是你个人使用,刁钻一点,一个脚本更改指向,一个正常启用,哈哈哈哈
页: [1] 2 3
查看完整版本: 网站定义了一个history()函数,导致脚本中无法访问Window.histor...