PageSourceSearch

https://e123.hk/modules/custom/e123_global_js_css/assets/change_font_size/js/font-size.js?v=3&v=1

js e123.hk collected 2026-09-24 10:00:41 UTC 13,609 bytes, 393 lines download raw bytes

1jQuery(function ($) {
2    var check_font_size = 0;
3    debugFontSize();
4    // **************************************************
5    // For font size UI on click change: start
6    // **************************************************
7    // For desktop
8    $('.header_menu ul.function_menu li:nth-child(1)').click(function (event) {
9        // if (check_font_size == 1) {
10        //     changeFontSize_my(-4);
11        // } else {
12        //     changeFontSize_my(-2);
13        // }
14        // check_font_size = -1;
15        // Set to font size 90
16        currentFontSize_my = 90;
17        saveSettings_my();
18        setFontSize_my(currentFontSize_my);
19        debugFontSize();
20        updateMenuColors();
21        return false;
22    });
23
24    $('.header_menu ul.function_menu li:nth-child(2)').click(function (event) {
25        // revertStyles_my(2);
26        // check_font_size = 0;
27        // Set to font size 100
28        currentFontSize_my = 100;
29        saveSettings_my();
30        setFontSize_my(currentFontSize_my);
31        debugFontSize();
32        updateMenuColors();
33        return false;
34    });
35
36    $('.header_menu ul.function_menu li:nth-child(3)').click(function (event) {
37        // if (check_font_size == -1) {
38        //     changeFontSize_my(4);
39        // } else {
40        //     changeFontSize_my(2);
41        // }
42        // check_font_size = 1;
43        // Set to font size 110
44        currentFontSize_my = 110;
45        saveSettings_my();
46        setFontSize_my(currentFontSize_my);
47        debugFontSize();
48        updateMenuColors();
49        return false;
50    });
51
52    // For mobile
53    $('.mobile_menu ul.function_menu li:nth-child(1)').click(function (event) {
54        // if (check_font_size == 1) {
55        //     changeFontSize_my(-4);
56        // } else {
57        //     changeFontSize_my(-2);
58        // }
59        // check_font_size = -1;
60        // Set to font size 90
61        currentFontSize_my = 90;
62        saveSettings_my();
63        // debugFontSize();
64        // Apply the font size to the mobile menu
65        setFontSize_my(currentFontSize_my);
66        debugFontSize();
67        updateMenuColors();
68        return false;
69    });
70
71    $('.mobile_menu ul.function_menu li:nth-child(2)').click(function (event) {
72        // revertStyles_my(2);
73        // check_font_size = 0;
74        // Set to font size 100
75        currentFontSize_my = 100;
76        saveSettings_my();
77        // debugFontSize();
78        // Apply the font size to the mobile menu
79        setFontSize_my(currentFontSize_my);
80        debugFontSize();
81        updateMenuColors();
82        return false;
83    });
84
85    $('.mobile_menu ul.function_menu li:nth-child(3)').click(function (event) {
86        // if (check_font_size == -1) {
87        //     changeFontSize_my(4);
88        // } else {
89        //     changeFontSize_my(2);
90        // }
91        // check_font_size = 1;
92        // Set to font size 110
93        currentFontSize_my = 110;
94        saveSettings_my();
95        // debugFontSize();
96        // Apply the font size to the mobile menu
97        setFontSize_my(currentFontSize_my);
98        debugFontSize();
99        updateMenuColors();
100        return false;
101    });
102    // **************************************************
103    // For font size UI on click change: end
104    // **************************************************
105
106
107    // **************************************************
108    // For font size change function: start
109    // **************************************************
110    // var tag = '##P#DIV';
111    var tag = '##P#A#H1#H2#H3#H4#H5#H6#SPAN#DIV#TD#LI#BUTTON#B#I#FONT#LABEL#STRONG#EM';
112    var class_ = '';
113    var id_ = '';
114    var max_ = parseInt('200');
115    var min_ = parseInt('90');
116    var all_elems = new Array();
117    var elements_id = null;
118    var al_id = false;
119    var al_class = false;
120    var allow_ids = new Array();
121    var allow_classes = new Array();
122    var x = '';
123
124    x = id_;
125    if (x)
126        while (x.indexOf('#') != -1) {
127            val = x.substr(0, x.indexOf('#'));
128            allow_ids.push(val);
129            x = x.substr(x.indexOf('#') + 1);
130        }
131    else
132        allow_ids[0] = false;
133
134    x = class_;
135    if (x)
136        while (x.indexOf('#') != -1) {
137            val = x.substr(0, x.indexOf('#'));
138            allow_classes.push(val);
139            x = x.substr(x.indexOf('#') + 1);
140        }
141    else
142        allow_classes[0] = false;
143
144    function getTextNodesIn(node, includeWhitespaceNodes, fontSize) {
145        var textNodes = [],
146            whitespace = /^\s*$/;
147
148        function getTextNodes(node) {
149            //alert(node.parentNode);
150
151            if (node.nodeType == 3) {
152                if (includeWhitespaceNodes || !whitespace.test(node.nodeValue)) {
153                    var parent_ = node.parentNode;
154                    if (parent_.nodeName == "FONT" && parent_.getAttribute("my") == "my") {
155                        if (((tag.indexOf('#' + parent_.parentNode.tagName) != -1) || (tag.indexOf("all") != -1)) && (parent_.parentNode.tagName != "SCRIPT")) {
156                            x = fontSize + "%";
157                            parent_.style.fontSize = x;
158                        }
159                    } else {
160                        if (((tag.indexOf('#' + parent_.tagName) != -1) || (tag.indexOf("all") != -1)) && (parent_.tagName != "SCRIPT")) {
161
162                            var newnode = document.createElement('font');
163                            newnode.setAttribute('style', 'font-size:' + fontSize + '%');
164                            newnode.setAttribute('my', 'my');
165
166                            var text = document.createTextNode(node.nodeValue);
167
168                            newnode.appendChild(text);
169                            parent_.replaceChild(newnode, node);
170                            textNodes.push(node);
171                        }
172                    }
173
174                }
175            } else {
176                for (var i = 0, len = node.childNodes.length; i < len; ++i) {
177                    getTextNodes(node.childNodes[i]);
178                }
179            }
180        }
181
182        getTextNodes(node);
183        return textNodes;
184    }
185
186    var prefsLoaded_my = false;
187    var defaultFontSize_my = 100;
188    var currentFontSize_my = defaultFontSize_my;
189
190
191    function changeFontSize_my(sizeDifference_my) {
192        currentFontSize_my = parseInt(currentFontSize_my) + parseInt(sizeDifference_my * 5);
193        if (currentFontSize_my > max_) {
194            currentFontSize_my = max_;
195        } else if (currentFontSize_my < min_) {
196            currentFontSize_my = min_;
197        }
198        setFontSize_my(currentFontSize_my);
199        // Add debug logging
200        // console.log('Current Font Size:', currentFontSize_my);
201        // console.log('Font Size Level:', Math.round((currentFontSize_my - 90) / 10) + 1);
202        debugFontSize();
203    }
204
205    function setFontSize_my(fontSize) {
206        var i = 0;
207        for (i = 0; i < all_elems.length; i++)
208            getTextNodesIn(all_elems[i], false, currentFontSize_my);
209    };
210
211
212    function revertStyles_my() {
213        currentFontSize_my = defaultFontSize_my;
214        setFontSize_my(0);
215    }
216
217
218    function createCookie_my(name, value, days) {
219        if (days) {
220            var date = new Date();
221            date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
222            var expires = "; expires=" + date.toGMTString();
223        } else expires = "";
224        // Add domain and secure attributes for better cross-tab support
225        document.cookie = name + "=" + value + expires + "; path=/; SameSite=Lax";
226    }
227
228    function readCookie_my(name) {
229        var nameEQ = name + "=";
230        var ca = document.cookie.split(';');
231        for (var i = 0; i < ca.length; i++) {
232            var c = ca[i];
233            while (c.charAt(0) == ' ') c = c.substring(1, c.length);
234            if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
235        }
236        return null;
237    }
238
239    // Add a function to sync font size across tabs
240    function syncFontSizeAcrossTabs() {
241        window.addEventListener('storage', function (e) {
242            if (e.key === 'fontSize') {
243                currentFontSize_my = parseInt(e.newValue);
244                setFontSize_my(currentFontSize_my);
245                updateMenuColors();
246            }
247        });
248    }
249
250    // Add a function to update menu colors based on font size
251    function updateMenuColors() {
252        switch (currentFontSize_my) {
253            case 90:
254                $('.header_menu ul.function_menu li:nth-child(1)').css("color", "#027765");
255                $('.header_menu ul.function_menu li:nth-child(2)').css("color", "#666666");
256                $('.header_menu ul.function_menu li:nth-child(3)').css("color", "#666666");
257                break;
258            case 100:
259                $('.header_menu ul.function_menu li:nth-child(1)').css("color", "#666666");
260                $('.header_menu ul.function_menu li:nth-child(2)').css("color", "#027765");
261                $('.header_menu ul.function_menu li:nth-child(3)').css("color", "#666666");
262                break;
263            case 110:
264                $('.header_menu ul.function_menu li:nth-child(1)').css("color", "#666666");
265                $('.header_menu ul.function_menu li:nth-child(2)').css("color", "#666666");
266                $('.header_menu ul.function_menu li:nth-child(3)').css("color", "#027765");
267                break;
268            default:
269                $('.header_menu ul.function_menu li:nth-child(1)').css("color", "#666666");
270                $('.header_menu ul.function_menu li:nth-child(2)').css("color", "#027765");
271                $('.header_menu ul.function_menu li:nth-child(3)').css("color", "#666666");
272                break;
273        }
274    }
275
276    function saveSettings_my() {
277        createCookie_my("fontSize", currentFontSize_my, 365);
278        // Also save to local-Storage for cross-tab sync
279        localStorage.setItem('fontSize', currentFontSize_my);
280    }
281
282    function setUserOptions_my() {
283        if (!prefsLoaded_my) {
284            var cookie = readCookie_my("fontSize");
285            currentFontSize_my = cookie ? parseInt(cookie) : defaultFontSize_my;
286
287            // Initialize cross-tab sync
288            syncFontSizeAcrossTabs();
289
290            // Update menu colors based on current font size
291            updateMenuColors();
292
293            var i = 0;
294            for (i = 0; i < all_elems.length; i++) {
295                if (all_elems[i])
296                    setFontSize_my(all_elems[i], false, currentFontSize_my);
297            }
298            prefsLoaded_my = true;
299        }
300    }
301
302    function zoomOnload() {
303        if (allow_ids[0])
304            for (i = 0; i < allow_ids.length; i++) {
305                if (allow_ids[i]) {
306                    if (document.getElementById(allow_ids[i])) {
307                        all_elems.push(document.getElementById(allow_ids[i]));
308                    }
309                }
310            }
311
312        else {
313            al_id = true;
314        }
315
316        if (allow_classes[0])
317            for (i = 0; i < allow_classes.length; i++) {
318                if (allow_classes[i]) {
319                    if (getElementsByClassName(allow_classes[i])[0]) {
320                        var elements_class = new Array();
321                        elements_class = getElementsByClassName(allow_classes[i]);
322                        for (x = 0; x < elements_class.length; x++)
323                            all_elems.push(elements_class[x]);
324                    }
325                }
326
327
328            }
329
330        else {
331            al_class = true;
332        }
333
334        if (al_id && al_class)
335            all_elems[0] = document.body;
336        setUserOptions_my();
337    }
338
339
340    function zoomAddToOnload() {
341        if (zoomOldFunctionOnLoad) {
342            zoomOldFunctionOnLoad();
343        }
344        zoomOnload();
345    }
346
347    function zoomAddToOnUnload() {
348        if (zoomOldFunctionOnUnload) {
349            zoomOldFunctionOnUnload();
350        }
351        saveSettings_my();
352    }
353
354    function zoomLoadBody() {
355        zoomOldFunctionOnLoad = window.onload;
356        zoomOldFunctionOnUnload = window.onunload;
357        window.onload = zoomAddToOnload;
358        window.onunload = zoomAddToOnUnload;
359    }
360
361    var zoomOldFunctionOnLoad = null;
362    var zoomOldFunctionOnUnload = null;
363
364    zoomLoadBody();
365    // **************************************************
366    // For font size change function: end
367    // **************************************************
368
369    // **************************************************
370    // Add debug function to check font size: start
371    // **************************************************
372    function debugFontSize() {
373        // Get the font size from localStorage
374        var localStorageFontSize = localStorage.getItem('fontSize');
375        var debugInfo =
376            'Current Font Size: ' + currentFontSize_my + '-------' +
377            'Font Size Level: ' + Math.round((currentFontSize_my - 90) / 10) + '-------' +
378            'Cookie: ' + readCookie_my("fontSize") + '-------' +
379            'localStorage: ' + localStorageFontSize;
380        // // Display the above information 
381        // if ($('.font-size-debug').length > 0) {
382        //     $('.font-size-debug').text(debugInfo);
383        // } else {
384        //     $('.site-logo').after('<span class="font-size-debug">' + debugInfo + '</span>');
385        // }
386    }
387
388    // Make debug function globally accessible
389    window.debugFontSize = debugFontSize;
390    // **************************************************
391    // Add debug function to check font size: end
392    // **************************************************
393});

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.