PageSourceSearch

https://wx-chevalier.github.io/assets/inject-github-card.js

js wx-chevalier.github.io collected 2026-10-03 10:11:11 UTC 3,173 bytes, 123 lines download raw bytes

1window.drawWidgets = function(d) {
2  var base = "./widgets/github-cards/";
3
4  var i,
5    count = 0;
6
7  var metas = d.getElementsByTagName("meta");
8  var client_url, client_id, client_secret, client_theme;
9  for (i = 0; i < metas.length; i++) {
10    var n = metas[i].getAttribute("name");
11    var c = metas[i].getAttribute("content");
12    if (n === "gc:url") {
13      client_url = c;
14    } else if (n === "gc:base") {
15      base = c;
16    } else if (n === "gc:client-id") {
17      client_id = c;
18    } else if (n === "gc:client-secret") {
19      client_secret = c;
20    } else if (n === "gc:theme") {
21      client_theme = c;
22    }
23  }
24
25  function queryclass(name) {
26    if (d.querySelectorAll) {
27      return d.querySelectorAll("." + name);
28    }
29    var elements = d.getElementsByTagName("div");
30    var ret = [];
31    for (i = 0; i < elements.length; i++) {
32      if (~elements[i].className.split(" ").indexOf(name)) {
33        ret.push(elements[i]);
34      }
35    }
36    return ret;
37  }
38
39  function querydata(element, name) {
40    return element.getAttribute("data-" + name);
41  }
42
43  function heighty(iframe) {
44    if (window.addEventListener) {
45      window.addEventListener(
46        "message",
47        function(e) {
48          if (iframe.id === e.data.sender) {
49            iframe.height = e.data.height;
50          }
51        },
52        false
53      );
54    }
55  }
56
57  function render(card, cardurl) {
58    cardurl = cardurl || client_url;
59    if (!cardurl) {
60      var theme = querydata(card, "theme") || client_theme || "default";
61      cardurl = base + "cards/" + theme + ".html";
62    }
63    var user = querydata(card, "user");
64    var repo = querydata(card, "repo");
65    var github = querydata(card, "github");
66    if (github) {
67      github = github.split("/");
68      if (github.length && !user) {
69        user = github[0];
70        repo = repo || github[1];
71      }
72    }
73    if (!user) {
74      return;
75    }
76
77    count += 1;
78    var width = querydata(card, "width");
79    var height = querydata(card, "height");
80    var target = querydata(card, "target");
81
82    var key = querydata(card, "client-id") || client_id;
83    var secret = querydata(card, "client-secret") || client_secret;
84
85    var identity = "ghcard-" + user + "-" + count;
86
87    var iframe = d.createElement("iframe");
88    iframe.setAttribute("id", identity);
89    iframe.setAttribute("frameborder", 0);
90    iframe.setAttribute("scrolling", 0);
91    iframe.setAttribute("allowtransparency", true);
92
93    var url = cardurl + "?user=" + user + "&identity=" + identity;
94    if (repo) {
95      url += "&repo=" + repo;
96    }
97    if (target) {
98      url += "&target=" + target;
99    }
100    if (key && secret) {
101      url += "&client_id=" + key + "&client_secret=" + secret;
102    }
103    iframe.src = url;
104    iframe.width = width || Math.min(card.parentNode.clientWidth || 400, 400);
105    if (height) {
106      iframe.height = height;
107    }
108    heighty(iframe);
109    card.parentNode.replaceChild(iframe, card);
110    return iframe;
111  }
112
113  var cards = queryclass("github-card");
114  for (i = 0; i < cards.length; i++) {
115    render(cards[i]);
116  }
117
118  if (window.githubCard) {
119    window.githubCard.render = render;
120  }
121};
122
123drawWidgets(window.document)

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.