PageSourceSearch

https://www.staffsunion.com/stylesheet/novus/tiktoknewsarticle.js?v=2

js staffsunion.com collected 2026-10-02 08:18:41 UTC 4,000 bytes, 129 lines download raw bytes

1(function () {
2  var SETTINGS = {
3    maxWidth: 420,
4    rememberChoice: true,                  // set false if you don't want it remembered
5    rememberKey: "su_tiktok_consent_v1",   // storage key
6    buttonText: "Load TikTok video",
7    titleText: "TikTok video",
8    bodyText: "This content is hosted by TikTok. Loading it may set cookies.",
9    linkText: "Open on TikTok instead"
10  };
11
12  function hasConsent() {
13    if (!SETTINGS.rememberChoice) return false;
14    try { return localStorage.getItem(SETTINGS.rememberKey) === "1"; }
15    catch (e) { return false; }
16  }
17
18  function setConsent() {
19    if (!SETTINGS.rememberChoice) return;
20    try { localStorage.setItem(SETTINGS.rememberKey, "1"); }
21    catch (e) {}
22  }
23
24  function loadTikTokScript(cb) {
25    if (document.querySelector('script[src*="tiktok.com/embed.js"]')) {
26      cb && cb();
27      return;
28    }
29    var s = document.createElement("script");
30    s.async = true;
31    s.src = "https://www.tiktok.com/embed.js";
32    s.onload = function () { cb && cb(); };
33    document.body.appendChild(s);
34  }
35
36  function getVideoId(url) {
37    var m = (url || "").match(/\/video\/(\d+)/);
38    return m ? m[1] : "";
39  }
40
41  function renderPlaceholder(el) {
42    var url = el.getAttribute("data-tiktok-url") || "";
43    if (!url) return;
44
45    el.style.maxWidth = SETTINGS.maxWidth + "px";
46    el.style.margin = "0 auto";
47    el.style.border = "1px solid #ddd";
48    el.style.borderRadius = "12px";
49    el.style.padding = "16px";
50
51    el.innerHTML =
52      '<div class="su-tiktok__inner">' +
53        '<p style="margin:0 0 6px;"><strong>' + SETTINGS.titleText + "</strong></p>" +
54        '<p style="margin:0 0 12px;">' + SETTINGS.bodyText + "</p>" +
55        '<button type="button" class="su-tiktok__btn" style="padding:10px 14px;border-radius:10px;cursor:pointer;">' +
56          SETTINGS.buttonText +
57        "</button>" +
58        '<p style="margin:12px 0 0;">' +
59          '<a href="' + url + '" target="_blank" rel="noopener">' + SETTINGS.linkText + "</a>" +
60        "</p>" +
61      "</div>";
62  }
63
64  function mountEmbed(el) {
65    var url = el.getAttribute("data-tiktok-url") || "";
66    var videoId = getVideoId(url);
67    if (!url || !videoId) return;
68
69    el.innerHTML =
70      '<blockquote class="tiktok-embed" cite="' + url + '" data-video-id="' + videoId + '" style="max-width:605px;min-width:325px;">' +
71        "<section></section>" +
72      "</blockquote>";
73
74    loadTikTokScript(function () {
75      if (window.tiktokEmbed && typeof window.tiktokEmbed.load === "function") {
76        window.tiktokEmbed.load();
77      }
78    });
79  }
80
81  function initAll() {
82    var els = document.querySelectorAll(".su-tiktok[data-tiktok-url]");
83    els.forEach(function (el) {
84      // Avoid re-initialising
85      if (el.getAttribute("data-su-tiktok-ready") === "1") return;
86      el.setAttribute("data-su-tiktok-ready", "1");
87
88      if (hasConsent()) {
89        mountEmbed(el);
90      } else {
91        renderPlaceholder(el);
92      }
93    });
94  }
95
96  function onClick(e) {
97    var btn = e.target.closest(".su-tiktok__btn");
98    if (!btn) return;
99
100    var wrap = btn.closest(".su-tiktok[data-tiktok-url]");
101    if (!wrap) return;
102
103    // User action = permission to load third-party content
104    setConsent();
105    mountEmbed(wrap);
106
107    // If you want: also load all other TikToks on the page after consent
108    if (SETTINGS.rememberChoice) {
109      document.querySelectorAll(".su-tiktok[data-tiktok-url]").forEach(function (el) {
110        if (el !== wrap) mountEmbed(el);
111      });
112    }
113  }
114
115  function start() {
116    initAll();
117    document.addEventListener("click", onClick);
118
119    // In case the platform injects content late (common on MSL pages)
120    setTimeout(initAll, 500);
121    setTimeout(initAll, 1500);
122  }
123
124  if (document.readyState === "loading") {
125    document.addEventListener("DOMContentLoaded", start);
126  } else {
127    start();
128  }
129})();

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.