PageSourceSearch

https://citizenshipapp.ca/assets/js/utility.js

js citizenshipapp.ca collected 2026-10-02 00:26:34 UTC 14,651 bytes, 495 lines download raw bytes

1/**
2 * Created by Amir MB on 07/09/2017.
3 */
4
5var URL = `https://${injected.app.data.meta.dedicatedDomain ?? "app.wisdom.reev.ca"}/api/`;
6var animationTime = 300
7
8function elm(id) {
9    return document.getElementById(id);
10}
11
12function ajax(data, url, method, callBack = (json)=>{}) {
13    var xhttp = new XMLHttpRequest();
14    console.log("URL: ", url);
15    console.log("DATA: ", data);
16    xhttp.onreadystatechange = function() {
17        if (this.readyState === 4 && this.status <= 500){
18            console.log("Response: ", this.responseText);
19            callBack(this.responseText);
20        }
21        else if(this.readyState === 4) {
22            console.log("Code: ", this.status);
23            console.log("Response: ", this.responseText);
24            Swal.fire({
25                text: "Sorry, something went wrong, please try again.",
26                icon: "error",
27                buttonsStyling: false,
28                confirmButtonText: "Ok, got it!",
29                customClass: {
30                    confirmButton: "btn font-weight-bold btn-light-primary"
31                }
32            }).then(function () {
33                KTUtil.scrollTop();
34            });
35        }
36    };
37    xhttp.open(method, url, true);
38    xhttp.setRequestHeader("X-Requested-With", "XMLHttpRequest");
39    xhttp.withCredentials = true;
40    if(data)
41        xhttp.setRequestHeader("Content-Type", "application/json");
42    xhttp.send(data);
43}
44
45function post(data, des, callBack = (json)=>{}) {
46    ajax(JSON.stringify(data), des, "POST", callBack);
47}
48
49function get(url, callBack = (json)=>{}){
50    ajax(null, url, "GET", callBack);
51}
52
53function put(data, des, callBack = (json)=>{}) {
54    ajax(JSON.stringify(data), des, "PUT", callBack);
55}
56
57function del(data, des, callBack = (json)=>{}) {
58    ajax(JSON.stringify(data), des, "DELETE", callBack);
59}
60
61
62HTMLElement.prototype.addMultipleChild = function (...children) {
63    for (var child of children)
64        this.appendChild(child);
65}
66
67function getParameterByName(name, url) {
68    if (!url) url = window.location.href;
69    name = name.replace(/[\[\]]/g, '\\$&');
70    var regex = new RegExp('[?&]' + name + '(=([^&#]*)|&|#|$)'),
71        results = regex.exec(url);
72    if (!results) return null;
73    if (!results[2]) return '';
74    return decodeURIComponent(results[2].replace(/\+/g, ' '));
75}
76
77function getLastUrlString(url) {
78    if (!url) url = window.location.href;
79    return decodeURIComponent(/[^/]*$/.exec(url)[0]);
80}
81
82function getUrlString(url) {
83    if (!url) url = window.location.href;
84    let url_parts = url.toString().split("/").reverse();
85    return url_parts;
86}
87
88function getStats() {
89    var stat = {
90        os: "undefined",
91        os_version: "undefined",
92        device: "undefined",
93        app_version: "0.0.1"
94    };
95    var userAgent = window.navigator.userAgent,
96        platform = window.navigator.platform,
97        macOsPlatforms = ['Macintosh', 'MacIntel', 'MacPPC', 'Mac68K'],
98        windowsPlatforms = ['Win32', 'Win64', 'Windows', 'WinCE'],
99        iosPlatforms = ['iPhone', 'iPad', 'iPod'];
100
101    var os = "undefined";
102
103    if (macOsPlatforms.indexOf(platform) !== -1)
104        os = 'Mac OS';
105    else if (iosPlatforms.indexOf(platform) !== -1)
106        os = 'iOS';
107    else if (windowsPlatforms.indexOf(platform) !== -1)
108        os = 'Windows';
109    else if (/Android/.test(userAgent))
110        os = 'Android';
111    else if (!os && /Linux/.test(platform))
112        os = 'Linux';
113
114    stat.os = os;
115
116    if(navigator.userAgent)
117        stat.os_version = navigator.userAgent;
118
119    var device = "undefined";
120
121    if((navigator.userAgent.indexOf("Opera") || navigator.userAgent.indexOf('OPR')) != -1 )
122        device = 'Opera';
123    else if(navigator.userAgent.indexOf("Chrome") != -1 )
124        device = 'Chrome';
125    else if(navigator.userAgent.indexOf("Safari") != -1)
126        device = 'Safari';
127    else if(navigator.userAgent.indexOf("Firefox") != -1 )
128        device = 'Firefox';
129    else if((navigator.userAgent.indexOf("MSIE") != -1 ) || (!!document.documentMode == true )) //IF IE > 10
130        device = 'IE';
131
132    stat.device = device;
133
134    return stat;
135}
136
137function randomArrayShuffle(array) {
138    var currentIndex = array.length, temporaryValue, randomIndex;
139    var newArray = array.slice();
140    while (0 !== currentIndex) {
141        randomIndex = Math.floor(Math.random() * currentIndex);
142        currentIndex -= 1;
143        temporaryValue = newArray[currentIndex];
144        newArray[currentIndex] = newArray[randomIndex];
145        newArray[randomIndex] = temporaryValue;
146    }
147    return newArray;
148}
149
150function randomIntFromInterval(min, max) {
151    return Math.floor(Math.random() * (max - min + 1) + min)
152}
153
154class Stack {
155    constructor(){
156        this.data = [];
157        this.top = 0;
158    }
159    push(element) {
160        this.data[this.top] = element;
161        this.top = this.top + 1;
162    }
163    length() {
164        return this.top;
165    }
166    peek() {
167        return this.data[this.top-1];
168    }
169    isEmpty() {
170        return this.top === 0;
171    }
172    pop() {
173        if( this.isEmpty() === false ) {
174            this.top = this.top -1;
175            return this.data.pop(); // removes the last element
176        }
177    }
178    print() {
179        var top = this.top - 1; // because top points to index where new    element to be inserted
180        while(top >= 0) { // print upto 0th index
181            console.log(this.data[top]);
182            top--;
183        }
184    }
185    reverse() {
186        this._reverse(this.top - 1 );
187    }
188    _reverse(index) {
189        if(index != 0) {
190            this._reverse(index-1);
191        }
192        console.log(this.data[index]);
193    }
194}
195
196// Enable or Disable a Button loading State
197function loadingButton(btn, state) {
198    if (state)
199        btn.addClass('button--loading').prop('disabled', true);
200    else
201        btn.removeClass('button--loading').prop('disabled', false);
202}
203
204var countdownIntervalHandle = undefined
205
206function countdownMaker(minutes) {
207    function tick(){
208        // grab the h1
209        var timeDisplay = document.getElementById("time-left-counter");
210
211        // turn the seconds into mm:ss
212        var min = Math.floor(secondsRemaining / 60);
213        var sec = secondsRemaining - (min * 60);
214
215        //add a leading zero (as a string value) if seconds less than 10
216        if (sec < 10) {
217            sec = "0" + sec;
218        }
219
220        // concatenate with colon
221        var message = min.toString() + ":" + sec;
222
223        // now change the display
224        timeDisplay.innerHTML = message;
225
226        // stop is down to zero
227        if (secondsRemaining === 0){
228            $('#time-passed-modal').modal('show');
229            clearInterval(countdownIntervalHandle);
230        }
231
232        //subtract from seconds remaining
233        secondsRemaining--;
234
235    }
236
237    var secondsRemaining = minutes * 60;
238    countdownIntervalHandle = setInterval(tick, 1000);
239
240}
241
242function timeSpentMaker() {
243    function tick(){
244        // grab the h1
245        var timeDisplay = document.getElementById("time-left-counter");
246
247        // turn the seconds into mm:ss
248        var min = Math.floor(secondsRemaining / 60);
249        var sec = secondsRemaining - (min * 60);
250
251        //add a leading zero (as a string value) if seconds less than 10
252        if (sec < 10) {
253            sec = "0" + sec;
254        }
255
256        // concatenate with colon
257        var message = min.toString() + ":" + sec;
258
259        // now change the display
260        timeDisplay.innerHTML = message;
261
262        //subtract from seconds remaining
263        secondsRemaining++;
264
265    }
266
267    var secondsRemaining = 0;
268    countdownIntervalHandle = setInterval(tick, 1000);
269
270}
271
272function loadJS(FILE_URL, async = true) {
273    let scriptEle = document.createElement("script");
274
275    scriptEle.setAttribute("src", FILE_URL);
276    // scriptEle.setAttribute("async", async);
277
278    document.body.appendChild(scriptEle);
279
280    // success event
281    scriptEle.addEventListener("load", () => {
282        console.log("File loaded")
283    });
284    // error event
285    scriptEle.addEventListener("error", (ev) => {
286        console.log("Error on loading file", ev);
287    });
288}
289
290class Tag {
291    static types = {};
292
293    constructor(attributes, value) {
294        this.attributes = attributes;
295        this.value = value;
296        this.children = [];
297        totalInArticleAdsense = 5;
298    }
299
300    // putInArticleAdsense() {
301    //     if (!premiumUser && adSenseEnable && totalInArticleAdsense >= 0) {
302    //         totalInArticleAdsense--;
303    //         const adv = document.createElement('div');
304    //         adv.classList.add('mb-5', `article-${totalInArticleAdsense}-adsense-wrapper`);
305    //         adv.innerHTML = `<ins class="adsbygoogle"
306    //              style="display:block; text-align:center;"
307    //              data-ad-layout="in-article"
308    //              data-ad-format="fluid"
309    //              data-ad-client="ca-pub-1870465747934285"
310    //              data-ad-slot="8490247075"></ins>`;
311    //         return adv;
312    //     }
313    //     return null;
314    // }
315
316    static create(node) {
317        const instantiate = Tag.types[node.nodeType === 1 ? node.nodeName.toString() : ""] ?? Plain;
318        let attrs = {};
319
320        if (node.nodeType === 1)
321            attrs = node.attributes;
322
323        const value = node.nodeType === 3 ? node.nodeValue : "";
324        const tag = new instantiate(attrs, value);
325
326        for (const item of node.childNodes) {
327            tag.children.push(Tag.create(item));
328        }
329
330
331        return tag;
332    }
333
334    static parse(data) {
335        const parser = new DOMParser();
336        const doc = parser.parseFromString(data, "text/xml");
337        return Tag.create(doc.getElementsByTagName('text')[0]).build();
338    }
339
340    build(context={}) {};
341}
342
343class Heading extends Tag {
344    build() {
345        // const parent = document.createElement("div");
346        // parent.appendChild(this.putInArticleAdsense());
347        const heading = document.createElement("h3");
348        heading.classList.add('font-size-h2');
349        this.children.forEach(item => heading.appendChild(item.build()));
350        // parent.appendChild(heading);
351        return heading;
352    }
353}
354
355class Bold extends Tag {
356    build() {
357        const strong = document.createElement("strong");
358        this.children.forEach(item => strong.appendChild(item.build()));
359        return strong;
360    }
361}
362
363class Link extends Tag {
364    build() {
365        const a = document.createElement("a");
366        this.children.forEach(item => a.appendChild(item.build()));
367        a.href = this.attributes["href"].value;
368        a.target = "_blank";
369        return a;
370    }
371}
372
373class Plain extends Tag {
374    build() {
375        const span = document.createElement("span");
376        span.innerText = this.value;
377        return span;
378    }
379}
380
381class Box extends Tag {
382    build() {
383        const div = document.createElement("div");
384        this.children.forEach(item => div.appendChild(item.build()));
385        return div;
386    }
387}
388
389class UnderLine extends Tag {
390    build() {
391        const u = document.createElement("u");
392        this.children.forEach(item => u.appendChild(item.build()));
393        return u;
394    }
395}
396
397class Li extends Tag {
398    build() {
399        const ul = document.createElement('ul');
400        const li = document.createElement('li');
401        this.children.forEach(item => li.appendChild(item.build()));
402        ul.appendChild(li);
403        return ul;
404    }
405}
406
407class GlossaryReference extends UnderLine {
408    build() {
409        const u = super.build();
410        // u.classList.add('');
411        // u.dataset.definition = this.attributes["def"].value;
412        u.classList.add('border-bottom-dashed', 'text-decoration-none', 'border-secondary')
413        u.title = this.attributes["def"].value;
414        u.dataset.toggle = 'tooltip';
415        return u;
416    }
417}
418
419class Color extends Tag {
420    build() {
421        const span = document.createElement("span");
422        this.children.forEach(item => span.appendChild(item.build()));
423        span.style.color = "";
424        return span;
425    }
426}
427
428class Row extends Tag {
429    build(context) {
430        const div = document.createElement("div");
431        div.classList.add("row");
432        if (!this.attributes.width || this.attributes.width != '100') {
433            div.classList.add('col-12', 'col-md-12', 'col-lg-10', 'col-xl-8', 'mx-auto')
434        }
435        if (!context)
436            context = {}
437        context.is_inside_a_row = true
438        console.log(this.children)
439        this.children.forEach(item => {
440            // alert(item.value)
441            // alert(item.value.trim())
442            // alert(item.value.trim().length)
443            if (!(item instanceof Plain) || item.value.trim().length > 0) {
444                const box = document.createElement('div');
445                box.classList.add('col');
446                box.appendChild(item.build(context));
447                div.appendChild(box);
448            }
449        });
450        return div;
451    }
452}
453
454class Image extends Tag {
455    build(context) {
456        const is_inside_a_row = context ? (context.is_inside_a_row ?? false) : false
457        const div = document.createElement("div");
458        const fig = document.createElement("figure");
459        const img = document.createElement("img");
460        const fig_caption = document.createElement("figcaption");
461        this.children.forEach(item => fig_caption.appendChild(item.build()));
462        img.src = this.attributes.url.value;
463        if (!is_inside_a_row && (!this.attributes.width || this.attributes.width != '100')) {
464            fig.classList.add('col-md-10', 'col-lg-8', 'col-xl-6')
465        }
466        img.classList.add('rounded', 'w-100')
467        fig_caption.classList.add('text-secondary', 'px-2', 'opacity-50', 'font-size-h6', 'text-left', 'py-2')
468        fig.classList.add('my-4', 'mx-auto', 'col-12')
469        div.classList.add('text-center', 'row')
470        fig.appendChild(img)
471        fig.appendChild(fig_caption)
472        div.appendChild(fig)
473        return div;
474    }
475}
476
477
478Tag.types = {
479    'h': Heading,
480    'b': Bold,
481    'a': Link,
482    'u': UnderLine,
483    'g': GlossaryReference,
484    'li': Li,
485    'lii': Li,
486    'text': Box,
487    'color': Color,
488    'image': Image,
489    'row': Row,
490};
491
492function  init() {
493}
494
495init();

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.