(Hintergrund: Ich habe versucht, den hier gefundenen JS-Code zu verwenden https://github.com/refined-github/refined-github/issues/1892, habe aber Lesezeichen verwendet, um alle Kommentare in die GitHub-PR zu laden) p>
Ich habe den folgenden JS-Code, der gut funktioniert, wenn er in die Konsole (Chrome) eingefügt wird.
(() => { let tryAttempts = 0; function loadComments () { let needRescheduling = false; const buttons = document.querySelectorAll(".ajax-pagination-btn[data-disable-with]") buttons.forEach((button) => { button.click(); needRescheduling = true; tryAttempts = 0; }) if (needRescheduling || tryAttempts < 5) { if (needRescheduling) { console.log("Loading comments.") } else { console.log("Looking for more to load."); } tryAttempts++; setTimeout(loadComments, 500) } else { console.log("All comments loaded."); const resolvedButtons = document.querySelectorAll(".js-toggle-outdated-comments[data-view-component]"); resolvedButtons.forEach((button) => { button.click(); }) console.log("All resolved comments loaded.") } } loadComments(); })();
Dann habe ich versucht, es in Chrome mit einem Lesezeichen zu versehen, um es in
zu konvertierenjavascript: (() => { let tryAttempts = 0; function loadComments () { let needRescheduling = false; const buttons = document.querySelectorAll(".ajax-pagination-btn[data-disable-with]") buttons.forEach((button) => { button.click(); needRescheduling = true; tryAttempts = 0; }) if (needRescheduling || tryAttempts < 5) { if (needRescheduling) { console.log("Loading comments.") } else { console.log("Looking for more to load."); } tryAttempts++; setTimeout(loadComments, 500) } else { console.log("All comments loaded."); const resolvedButtons = document.querySelectorAll(".js-toggle-outdated-comments[data-view-component]"); resolvedButtons.forEach((button) => { button.click(); }) console.log("All resolved comments loaded.") } } loadComments();})();
Dies führt zu einem Syntaxfehler. Uncaught SyntaxError:意外的标识符“按钮”
Was mache ich hier falsch?
您的代码取决于自动分号插入.
即您的代码中有些地方使用换行而不是分号。
无论您使用什么方法将其转换为小书签,都会删除这些新行,但无法用分号替换它们。
您需要手动添加分号或修复方法以便自动插入分号。