| 1 |
window.addEventListener("load", function () { |
| 2 |
const url = new URL(window.location.href); |
| 3 |
|
| 4 |
if (!url.searchParams.has("spblock_inserter")) return; |
| 5 |
|
| 6 |
function tryClick() { |
| 7 |
const btn = document.querySelector(".editor-document-tools__inserter-toggle"); |
| 8 |
if (btn) { |
| 9 |
btn.click(); |
| 10 |
url.searchParams.delete("spblock_inserter"); |
| 11 |
history.replaceState(null, "", url.toString()); |
| 12 |
return true; |
| 13 |
} |
| 14 |
return false; |
| 15 |
} |
| 16 |
|
| 17 |
// Try every 100ms for up to 2 seconds |
| 18 |
let attempts = 0; |
| 19 |
const interval = setInterval(() => { |
| 20 |
attempts++; |
| 21 |
if (tryClick() || attempts > 20) { |
| 22 |
clearInterval(interval); |
| 23 |
} |
| 24 |
}, 100); |
| 25 |
}); |
| 26 |
|