PageSourceSearch

https://cas.univ-littoral.fr/js/cas-cd46228f2a9b608731f0c9dacfb9758c.js

js univ-littoral.fr collected 2026-10-01 11:25:29 UTC 12,311 bytes, 376 lines download raw bytes

1function randomWord() {
2    let things = ["admiring", "adoring", "affectionate", "agitated", "amazing",
3        "angry", "awesome", "beautiful", "blissful", "bold", "boring",
4        "brave", "busy", "charming", "clever", "cool", "compassionate", "competent",
5        "confident", "dazzling", "determined", "sweet", "sad", "silly",
6        "relaxed", "romantic", "sad", "serene", "sharp", "quirky", "scared",
7        "sleepy", "stoic", "strange", "suspicious", "sweet", "tender", "thirsty",
8        "trusting", "unruffled", "upbeat", "vibrant", "vigilant", "vigorous",
9        "wizardly", "wonderful", "youthful", "zealous", "zen"];
10
11    let names = ["austin", "borg", "bohr", "wozniak", "bose", "wu", "wing", "wilson",
12        "boyd", "guss", "jobs", "hawking", "hertz", "ford", "solomon", "spence",
13        "turing", "torvalds", "morse", "ford", "penicillin", "lovelace", "davinci",
14        "darwin", "buck", "brown", "benz", "boss", "allen", "gates", "bose",
15        "edison", "einstein", "feynman", "ferman", "franklin", "lincoln", "jefferson",
16        "mandela", "gandhi", "curie", "newton", "tesla", "faraday", "bell",
17        "aristotle", "hubble", "nobel", "pascal", "washington", "galileo"];
18
19    const n1 = things[Math.floor(Math.random() * things.length)];
20    const n2 = names[Math.floor(Math.random() * names.length)];
21    return `${n1}_${n2}`;
22}
23
24function copyClipboard(element) {
25    element.select();
26    element.setSelectionRange(0, 99999);
27    document.execCommand("copy");
28}
29
30function getLastTwoWords(str) {
31    const parts = str.split(".");
32    return parts.slice(-2).join(".");
33}
34
35function getLastWord(str) {
36    const parts = str.split(".");
37    return parts.slice(-1).join(".");
38}
39
40function formatDateYearMonthDayHourMinute(date) {
41    const d = new Date(date);
42    const year = d.getFullYear();
43    const month = (d.getMonth() + 1).toString().padStart(2, "0"); // Months are zero-based
44    const day = d.getDate().toString().padStart(2, "0");
45    const hours = d.getHours().toString().padStart(2, "0");
46    const minutes = d.getMinutes().toString().padStart(2, "0");
47    return `${year}-${month}-${day} ${hours}:${minutes}`;
48}
49
50function formatDateYearMonthDay(date) {
51    const d = new Date(date);
52    const year = d.getFullYear();
53    const month = (d.getMonth() + 1).toString().padStart(2, "0");
54    const day = d.getDate().toString().padStart(2, "0");
55    return `${year}-${month}-${day}`;
56}
57
58function toKebabCase(str) {
59    return str
60        .replace(/([a-z0-9])([A-Z])/g, '$1-$2')
61        .replace(/[^a-zA-Z0-9.[\]]+/g, '-')
62        .replace(/^-+|-+$/g, '')
63        .toLowerCase();
64}
65
66
67function camelcaseToTitleCase(str) {
68    return str
69        .replace(/([A-Z])/g, " $1")
70        .replace(/^./, char => char.toUpperCase())
71        .trim();
72}
73
74function flattenJSON(data) {
75    let result = {};
76    let l = undefined;
77
78    function recurse(cur, prop) {
79        if (Object(cur) !== cur) {
80            result[prop] = cur;
81        } else if (Array.isArray(cur)) {
82            for (let i = 0, l = cur.length; i < l; i++) {
83                recurse(cur[i], `${prop}[${i}]`);
84            }
85            if (l === 0) {
86                result[prop] = [];
87            }
88        } else {
89            let isEmpty = true;
90            for (let p in cur) {
91                isEmpty = false;
92                recurse(cur[p], prop ? `${prop}.${p}` : p);
93            }
94            if (isEmpty && prop) {
95                result[prop] = {};
96            }
97        }
98    }
99
100    recurse(data, "");
101    return result;
102}
103
104function convertMemoryToGB(memoryStr) {
105    const units = {
106        B: 1,
107        KB: 1024,
108        MB: 1024 ** 2,
109        GB: 1024 ** 3,
110        TB: 1024 ** 4
111    };
112    const regex = /(\d+(\.\d+)?)\s*(B|KB|MB|GB|TB)/i;
113    const match = memoryStr.match(regex);
114    const value = parseFloat(match[1]);
115    const unit = match[3].toUpperCase();
116    const bytes = value * units[unit];
117    return bytes / units.GB;
118}
119
120function isValidURL(str) {
121    let pattern = new RegExp("^(https?:\\/\\/)?" + // protocol
122        "((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.)+[a-z]{2,}|" + // domain name
123        "((\\d{1,3}\\.){3}\\d{1,3}))" + // OR ip (v4) address
124        "(\\:\\d+)?(\\/[-a-z\\d%_.~+]*)*" + // port and path
125        "(\\?[;&a-z\\d%_.~+=-]*)?" + // query string
126        "(\\#[-a-z\\d_]*)?$", "i"); // fragment locator
127    return !!pattern.test(str);
128}
129
130function requestGeoPosition() {
131    // console.log('Requesting GeoLocation data from the browser...');
132    if (navigator.geolocation) {
133        navigator.geolocation.watchPosition(showGeoPosition, logGeoLocationError,
134            {maximumAge: 600000, timeout: 5000, enableHighAccuracy: true});
135    } else {
136        console.log("Browser does not support Geo Location");
137    }
138}
139
140function logGeoLocationError(error) {
141    switch (error.code) {
142    case error.PERMISSION_DENIED:
143        console.log("User denied the request for GeoLocation.");
144        break;
145    case error.POSITION_UNAVAILABLE:
146        console.log("Location information is unavailable.");
147        break;
148    case error.TIMEOUT:
149        console.log("The request to get user location timed out.");
150        break;
151    default:
152        console.log("An unknown error occurred.");
153        break;
154    }
155}
156
157function showGeoPosition(position) {
158    let loc = `${position.coords.latitude},${position.coords.longitude},${position.coords.accuracy},${position.timestamp}`;
159    // console.log(`Tracking geolocation for ${loc}`);
160    $("[name=\"geolocation\"]").val(loc);
161}
162
163function getCookie(name) {
164    const value = `; ${document.cookie}`;
165    const parts = value.split(`; ${name}=`);
166    if (parts.length === 2) {
167        return parts.pop().split(';').shift();
168    }
169    return null;
170}
171
172function preserveAnchorTagOnForm() {
173    $("#fm1").submit(() => {
174        let location = self.document.location;
175
176        let action = $("#fm1").attr("action");
177        if (action === undefined) {
178            action = location.href;
179        } else {
180            action += location.search + encodeURIComponent(location.hash);
181        }
182        // console.log(`Preserving URL fragment in form action: ${action}`);
183        $("#fm1").attr("action", action);
184
185    });
186}
187
188function preventFormResubmission() {
189    $("form").submit(() => {
190        const dataDisableSubmitValue = $(this).attr('data-disable-submit');
191        if (dataDisableSubmitValue) {
192            $(":submit").attr("disabled", true);
193        }
194        let altText = $(":submit").attr("data-processing-text");
195        if (altText) {
196            $(":submit").attr("value", altText);
197        }
198        return true;
199    });
200}
201
202function writeToLocalStorage(browserStorage) {
203    if (typeof (Storage) === "undefined") {
204        console.log("Browser does not support local storage for write ops");
205    } else {
206        let payload = readFromLocalStorage(browserStorage);
207        window.localStorage.removeItem("CAS");
208        payload[browserStorage.context] = browserStorage.payload;
209        window.localStorage.setItem("CAS", JSON.stringify(payload));
210        // console.log(`Stored ${browserStorage.payload} in local storage under key ${browserStorage.context}`);
211    }
212}
213
214function readFromLocalStorage(browserStorage) {
215    if (typeof (Storage) === "undefined") {
216        console.log("Browser does not support local storage for read ops");
217        return null;
218    }
219    try {
220        let payload = window.localStorage.getItem("CAS");
221        // console.log(`Read ${payload} in local storage`);
222        return payload === null ? {} : JSON.parse(payload);
223    } catch (e) {
224        console.log(`Failed to read from local storage: ${e}`);
225        window.localStorage.removeItem("CAS");
226        return {};
227    }
228}
229
230function clearLocalStorage() {
231    if (typeof (Storage) === "undefined") {
232        console.log("Browser does not support local storage for write-ops");
233    } else {
234        window.localStorage.clear();
235    }
236}
237
238function writeToSessionStorage(browserStorage) {
239    if (typeof (Storage) === "undefined") {
240        console.log("Browser does not support session storage for write-ops");
241    } else {
242        let payload = readFromSessionStorage(browserStorage);
243        window.sessionStorage.removeItem("CAS");
244        payload[browserStorage.context] = browserStorage.payload;
245        window.sessionStorage.setItem("CAS", JSON.stringify(payload));
246        // console.log(`Stored ${browserStorage.payload} in session storage under key ${browserStorage.context}`);
247    }
248}
249
250function clearSessionStorage() {
251    if (typeof (Storage) === "undefined") {
252        console.log("Browser does not support session storage for write-ops");
253    } else {
254        window.sessionStorage.clear();
255        // console.log("Cleared session storage");
256    }
257}
258
259function readFromSessionStorage(browserStorage) {
260    if (typeof (Storage) === "undefined") {
261        console.log("Browser does not support session storage for read-ops");
262        return null;
263    }
264    try {
265        let payload = window.sessionStorage.getItem("CAS");
266        // console.log(`Read ${payload} in session storage`);
267        return payload === null ? {} : JSON.parse(payload);
268    } catch (e) {
269        console.log(`Failed to read from session storage: ${e}`);
270        window.sessionStorage.removeItem("CAS");
271        return {};
272    }
273}
274
275function loginFormSubmission() {
276    return true;
277}
278
279function resourceLoadedSuccessfully() {
280    $(document).ready(() => {
281        if (trackGeoLocation) {
282            requestGeoPosition();
283        }
284
285        if ($(":focus").length === 0) {
286            $("input:visible:enabled:first").focus();
287        }
288
289        try {
290            $("table.auto-init").DataTable();
291        } catch (e) {
292            console.log(`Failed to initialize DataTable: ${e}`);
293        }
294        preserveAnchorTagOnForm();
295        preventFormResubmission();
296        $("#fm1 input[name=\"username\"],[name=\"password\"]").trigger("input");
297        $("#fm1 input[name=\"username\"]").focus();
298
299        $(".reveal-password").on("click", function(ev) {
300            ev.preventDefault();
301
302            const btn  = $(this);
303            const pwd  = $(".pwd");
304            const icon = $(".reveal-password-icon");
305
306            if (pwd.attr("type") === "text") {
307                pwd.attr("type", "password");
308                icon.removeClass("mdi-eye-off").addClass("mdi-eye");
309                btn.attr('aria-pressed', false);
310            } else {
311                pwd.attr("type", "text");
312                icon.removeClass("mdi-eye").addClass("mdi-eye-off");
313                btn.attr('aria-pressed', true);
314            }
315        });
316
317        if (typeof hljs !== 'undefined') {
318            hljs.highlightAll();
319        }
320    });
321}
322
323function autoHideElement(id, timeout = 1500) {
324    let elementToFadeOut = document.getElementById(id);
325
326    function hideElement() {
327        $(elementToFadeOut).fadeOut(500);
328    }
329
330    setTimeout(hideElement, timeout);
331}
332
333function initializeAceEditor(id, mode="json") {
334    ace.require("ace/ext/language_tools");
335    const beautify = ace.require("ace/ext/beautify");
336    const editor = ace.edit(id);
337    editor.setTheme("ace/theme/cobalt");
338    editor.session.setMode(`ace/mode/${mode}`);
339    editor.session.setUseWrapMode(true);
340    editor.session.setTabSize(4);
341    editor.setShowPrintMargin(false);
342    editor.commands.addCommand({
343        name: "deleteLine",
344        bindKey: {
345            win: "Ctrl-Y",
346            mac: "Command-Y"
347        },
348        exec: editor => {
349            const cursorPosition = editor.getCursorPosition();
350            editor.session.remove({
351                start: {row: cursorPosition.row, column: 0},
352                end: {row: cursorPosition.row + 1, column: 0}
353            });
354        },
355        readOnly: false
356    });
357    editor.setOptions({
358        enableBasicAutocompletion: true,
359        enableLiveAutocompletion: true,
360        enableSnippets: true,
361        selectionStyle: "text",
362        highlightActiveLine: true,
363        highlightSelectedWord: true,
364        enableAutoIndent: true,
365        cursorStyle: "wide",
366        useSoftTabs: true,
367        hScrollBarAlwaysVisible: false,
368        showInvisibles: false,
369        animatedScroll: true,
370        highlightGutterLine: true,
371        showLineNumbers: true,
372        fontSize: "16px"
373    });
374    beautify.beautify(editor.session);
375    return editor;
376}

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.