MCPcopy Index your code
hub / github.com/Bistutu/FluentRead / checkRun

Function checkRun

userscripts.js:1805–1840  ·  view source on GitHub ↗
(callback)

Source from the content-addressed store, hash-verified

1803// region read
1804// read:异步返回 callback,表示是否需要拉取数据
1805function checkRun(callback) {
1806 // 1、检查缓存
1807 let pageMapCache = GM_getValue(checkKey, false);
1808 if (pageMapCache) {
1809 pageMapCache[url.host] ? callback(true) : callback(false);
1810 }
1811
1812 // 2、网络请求
1813 const lastRun = GM_getValue("lastRun", undefined);
1814 const now = new Date().getTime();
1815
1816 if (isEmpty(lastRun) || now - lastRun > expiringTime) {
1817 console.log("开始更新 preread 缓存");
1818 GM_xmlhttpRequest({
1819 method: POST,
1820 url: preread,
1821 onload: function (response) {
1822 // pagesMap 是新获取的数据,pageMapCache 是从缓存中获取的旧数据
1823 let pagesMap = JSON.parse(response.responseText).Data;
1824 pagesMap[url.host] ? callback(true) : callback(false);
1825 // 将 fluent_read_check 设置为新的缓存
1826 GM_setValue(checkKey, pagesMap);
1827 // 检查 preread 名单判断是否需要更新对应 host 的 read 数据
1828 const listValues = GM_listValues();
1829 listValues.forEach(host => {
1830 if (pageMapCache[host] !== pagesMap[host]) {
1831 GM_deleteValue(host);
1832 console.log("删除过期的缓存数据:", host);
1833 }
1834 });
1835 GM_setValue("lastRun", now.toString()); // 请求成功后设置当前时间
1836 },
1837 onerror: (error) => console.error("请求失败: ", error)
1838 });
1839 }
1840}
1841
1842// read:处理 DOM 更新
1843function handleDOMUpdate(node) {

Callers 1

userscripts.jsFile · 0.85

Calls 1

isEmptyFunction · 0.85

Tested by

no test coverage detected