Mostly this $ is not defined error occurs because jQuery is not loaded, however shouldn’t the header scripts be by default executed after jQuery is loaded?h.
תודה, אבל אם זה JavaScript זה עובד בסדר כשמשתמשים בו בקונסול המפתחים document.querySelector('.topic-list .topic-excerpt[href="/t/urltobechanged/8"]').setAttribute('href', "/t/newurltoset/17");
איכשהו כשזה נטען מכותרת ה-discourse, זה מוחזר כ-“Uncaught TypeError: document.querySelector(…) is null”, לא משנה אם אני עוטף את זה ב:
function doSomething() {
או
document.addEventListener("DOMContentLoaded", function(event)
יש למישהו מושג איך השורה הבודדת הזו לשינוי המאפיין href צריכה לרוץ כפי שהיא עובדת מצוין בקונסול המפתחים?
Since Discourse is an SPA, relying on the document “DOMContentLoaded” won’t be very helpful, since the document DOM is always “loaded” but the elements can be missing. Instead you’ll want to use Components as @merefield mentioned, or something like this: How do you force a script to refire on every page load in Discourse? - #5 by simon. This way every time the page changes, your code can check for the element you’re trying to change.