ads.js 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. // wwads.cn: above table of contents. Carbon Ads: below table of contents.
  2. (function () {
  3. "use strict";
  4. var CARBON_ID = "gogs-carbon-ad";
  5. var WWADS_ID = "gogs-wwads";
  6. // Load the wwads.cn global script (skipped on localhost — ad unit
  7. // 97 is registered for gogs.io and the API rejects other origins).
  8. var isProduction = location.hostname !== "localhost";
  9. if (isProduction) {
  10. var wwScript = document.createElement("script");
  11. wwScript.src = "https://cdn.wwads.cn/js/makemoney.js";
  12. wwScript.async = true;
  13. document.head.appendChild(wwScript);
  14. }
  15. function injectCarbonAd() {
  16. if (document.getElementById(CARBON_ID)) return;
  17. var toc = document.getElementById("table-of-contents");
  18. if (!toc) return;
  19. var container = document.createElement("div");
  20. container.id = CARBON_ID;
  21. var carbon = document.createElement("script");
  22. carbon.async = true;
  23. carbon.type = "text/javascript";
  24. carbon.src =
  25. "//cdn.carbonads.com/carbon.js?serve=CKYILK3U&placement=gogsio";
  26. carbon.id = "_carbonads_js";
  27. container.appendChild(carbon);
  28. toc.appendChild(container);
  29. }
  30. function injectWwads() {
  31. if (document.getElementById(WWADS_ID)) return;
  32. var toc = document.getElementById("table-of-contents");
  33. if (!toc) return;
  34. var container = document.createElement("div");
  35. container.id = WWADS_ID;
  36. var wwads = document.createElement("div");
  37. wwads.className = "wwads-cn wwads-horizontal";
  38. wwads.setAttribute("data-id", "97");
  39. container.appendChild(wwads);
  40. toc.insertBefore(container, toc.firstChild);
  41. }
  42. function injectAds() {
  43. injectCarbonAd();
  44. injectWwads();
  45. }
  46. // Re-inject when the content is replaced during SPA navigation.
  47. var debounce;
  48. new MutationObserver(function () {
  49. clearTimeout(debounce);
  50. debounce = setTimeout(injectAds, 200);
  51. }).observe(document.documentElement, { childList: true, subtree: true });
  52. injectAds();
  53. })();