PageSourceSearch

https://jn327.github.io/scripts/CommonElementsCreator.js

js jn327.github.io collected 2026-10-03 09:24:07 UTC 3,064 bytes, 121 lines download raw bytes

1var CommonElementsCreator = {};
2CommonElementsCreator.defaultTopBarParent = document.body;
3CommonElementsCreator.defaultCanvasParent = document.body;
4CommonElementsCreator.rootLocation;
5CommonElementsCreator.addedStyles = [];
6CommonElementsCreator.addedScripts = [];
7
8CommonElementsCreator.addLoadEvent = function(func)
9{
10  var oldonload = window.onload;
11  if (typeof window.onload != 'function')
12  {
13    window.onload = func;
14  }
15  else
16  {
17    window.onload = function()
18    {
19      if (oldonload)
20      {
21        oldonload();
22      }
23      func();
24    }
25  }
26}
27
28CommonElementsCreator.addFonts = function( theFonts )
29{
30    var l = theFonts.length;
31    var theLink;
32    for (var i = 0; i < l; i++ )
33    {
34      theLink = document.createElement('link');
35      theLink.href = theFonts[i];
36      theLink.rel = "stylesheet";
37      document.head.appendChild(theLink);
38    }
39}
40
41CommonElementsCreator.addStyles = function( theCss )
42{
43  var rootLocation = this.getRootLocation();
44
45  l = theCss.length;
46  for (var i = 0; i < l; i++ )
47  {
48    //Only add this style if it's not already been added!
49    if ( CommonElementsCreator.addedStyles.includes(theCss[i]) == false )
50    {
51      theLink = document.createElement('link');
52      theLink.href = rootLocation +"styles/" +theCss[i] +".css";
53      theLink.rel = "stylesheet";
54      document.head.appendChild(theLink);
55
56      CommonElementsCreator.addedStyles.push( theCss[i] );
57    }
58    else
59    {
60      console.log(rootLocation +"styles/" +theCss[i]+".css has already been added, we won't add this again.")
61    }
62  }
63}
64
65CommonElementsCreator.getRootLocation = function()
66{
67  var rootLocation = CommonElementsCreator.rootLocation;
68  if (rootLocation == undefined)
69  {
70    rootLocation = "";
71  }
72  else
73  {
74    return rootLocation;
75  }
76
77  if (window.location.protocol == "file:")
78  {
79    //TODO: Find a better way to get this, if we change folder location this breaks.
80    // using "" breaks if we go into a sub page.
81    rootLocation = "C:/Users/joshu/Documents/jn327.github.io/";
82  }
83  else
84  {
85    var pathname = window.location.pathname;
86    var res = pathname.match(new RegExp("/", "gi")) || [];
87    var currDepth = res.length;
88
89    for (var i = 1; i < currDepth; i++)
90    {
91      rootLocation += "../";
92    }
93  }
94
95  CommonElementsCreator.rootLocation = rootLocation;
96  return rootLocation;
97}
98
99CommonElementsCreator.appendScripts = function( includes )
100{
101  var rootLocation = this.getRootLocation();
102
103  var l = includes.length;
104  var theScript;
105  for (var i = 0; i < l; i++ )
106  {
107    if ( CommonElementsCreator.addedScripts.includes(includes[i]) == false )
108    {
109      theScript = document.createElement('script');
110      theScript.src = rootLocation+'scripts/'+includes[i]+'.js';
111      document.head.appendChild(theScript);
112    }
113    else
114    {
115      console.log(rootLocation+'scripts/'+includes[i]+".js has already been added, we won't add this again.")
116    }
117  }
118}
119
120CommonElementsCreator.addFonts( ["https://fonts.googleapis.com/css?family=Roboto:400,500&display=swap"] )
121CommonElementsCreator.addStyles( ["shared"] );

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.