PageSourceSearch

https://static.orangenews.hk/static/orange/js/common.js?v=1.2.8

js orangenews.hk collected 2026-09-24 18:16:35 UTC 11,940 bytes, 340 lines download raw bytes

1//var apiUrl="https://api.orangenews.hk/";
2//var apiUrl="http://127.0.0.1:8888/";
3// var apiUrl="https://test-api.orangenews.hk/";
4
5// 环境检测
6function getApiUrl() {
7    const hostname = window.location.hostname;
8    if (hostname === 'www.orangenews.hk') {
9        return 'https://api.orangenews.hk/';
10    } else if (hostname === 'test-www.orangenews.hk') {
11        return 'https://test-api.orangenews.hk/';
12    } else {
13        return 'https://test-api.orangenews.hk/';
14        // return 'http://localhost/';
15    }
16}
17
18// 敏感关键字检测
19function detectSqlInjectionKeywords(inputString) {
20    const sqlKeywords = [
21        /\bSELECT\b/i, /\bINSERT\b/i, /\bUPDATE\b/i, /\bDELETE\b/i, /\bDROP\b/i,
22        /\bUNION\b/i, /\bOR\b/i, /\bAND\b/i, /\bEXEC\b/i, /\bEXECUTE\b/i,
23        /\bCAST\b/i, /\bCONVERT\b/i, /\bDECLARE\b/i, /\bWAITFOR\b/i,
24        /\bXP_CMDSHELL\b/i, /\bINFORMATION_SCHEMA\b/i, /\bFROM\b/i,
25        /\bWHERE\b/i, /\bORDER BY\b/i, /\bGROUP BY\b/i, /\bHAVING\b/i,
26        /\b--\b/, /\/\*.*?\*\//, /\b\d+=\d+\b/, /\b'='\b/, /\b' OR '\b/i
27    ];
28
29    for (const keywordRegex of sqlKeywords) {
30        if (keywordRegex.test(inputString)) {
31            // console.log("SQL注入 keywords detected:", inputString);
32            return true; // 发现潜在的SQL注入关键字
33        }
34    }
35    return false; // 未发现
36}
37
38/**
39 * 校验用户名或搜索输入
40 * 1. 只允许输入:中文、英文、空格、下划线、数字、@符号、.句号
41 * 2. 不允许全为空格
42 * @param {string} inputString - 待校验的字符串
43 * @returns {boolean} - 如果输入合法返回 true,否则返回 false
44 */
45function isValidUsernameOrSearch(inputString) {
46    // 1. 基础校验:必须是字符串且不能为空
47    if (typeof inputString !== 'string' || inputString.length === 0) {
48        return false;
49    }
50
51    // 2. 排除全为空格的情况
52    // trim() 会移除字符串两端的空格,如果移除后长度为 0,说明原字符串全为空格
53    if (inputString.trim().length === 0) {
54        return false;
55    }
56
57    // 3. 字符范围校验:
58    // \u4e00-\u9fa5 : 中文字符范围
59    // a-zA-Z       : 英文字母
60    // 0-9          : 数字
61    //  _@.         : 空格、下划线、@符号、句号
62    const allowedPattern = /^[\u4e00-\u9fa5a-zA-Z0-9 _@.]+$/;
63
64    return allowedPattern.test(inputString);
65}
66
67
68// 设置API URL
69var apiUrl = getApiUrl();
70
71function getUser() {
72    const user = localStorage.getItem("User");
73    return JSON.parse(user);
74}
75
76function getToken() {
77    const token = localStorage.getItem("token");
78    return token;
79}
80
81function loginOut(url) {
82    if(getUser()!=null && getUser()!=""){
83        localStorage.removeItem("User");
84        localStorage.removeItem("token");
85        window.location.href =url;
86    }
87}
88
89function shareFaceBook(url, img) {
90    let toUrl = "https://www.facebook.com/dialog/feed?app_id=204519490467319&redirect_uri=" + url + "&link=" + url + "&picture=" + img + "&display=page&show_error=yes";
91    window.open(toUrl)
92}
93
94function shareWeibo(url) {
95    let toUrl = "http://service.weibo.com/share/share.php?url=" + url + "&type=button&language=zh_cn&searchPic=true&style=number";
96    window.open(toUrl)
97}
98
99function shareWeChat(type, obj) {
100    $('#qrcode').html("");
101    let url = "https://m.orangenews.hk/";
102    if (type == "zx" || type == "zt") {
103        url += "details?recommendId=" + obj.contentId;
104    }
105    if (type == "gzz") {
106        url += "gzzdetails?contentId=" + obj.contentId + "&penName=" + obj.userName;
107    }
108    if (type == "qa") {
109        url += "qadetails?problemId=" + obj.problemId;
110    }
111    if (type == "video") {
112        url += "videodetails?recommendId=" + obj.contentId;
113    }
114    if (type == "live") {
115        url += "livedetails?recommendId=" + obj.contentId;
116    }
117    $('#qrcode').qrcode({
118        render: "canvas",
119        width: 260,
120        height: 260,
121        text: encodeURI(url)
122    });
123}
124
125function shareWeChat(type, obj) {
126    $('#qrcode').html("");
127    let url = "https://m.orangenews.hk/";
128    if (type == "zx" || type == "zt") {
129        url += "details?recommendId=" + obj.contentId;
130    }
131    if (type == "gzz") {
132        url += "gzzdetails?contentId=" + obj.contentId + "&penName=" + obj.userName;
133    }
134    if (type == "qa") {
135        url += "qadetails?problemId=" + obj.problemId;
136    }
137    if (type == "video") {
138        url += "videodetails?recommendId=" + obj.contentId;
139    }
140    if (type == "live") {
141        url += "livedetails?recommendId=" + obj.contentId;
142    }
143    $('#qrcode').qrcode({
144        render: "canvas",
145        width: 260,
146        height: 260,
147        text: encodeURI(url)
148    });
149}
150
151function showWeChat(){
152    layer.open({
153        type: 1,
154        title: "掃描QR Code 關注橙新聞",
155        closeBtn: 1,
156        area: '277px',
157        shadeClose: true,
158        content: '<img src="https://static.orangenews.hk/static/orange/img/OrangeNewsAppQRCode.jpg" width="275px" height="275px">'
159    });
160}
161
162function openAd(obj) {
163    let advId=$(obj).attr("advId");
164    let link=$(obj).attr("link");
165    let linkType=$(obj).attr("linkType");
166    console.log(advId)
167    console.log(link)
168
169    if(advId!="" && advId!=null && link!="" && link!=null){
170        $.ajax({
171            type: "POST",
172            dataType: "json",
173            contentType: "application/x-www-form-urlencoded;charset=UTF-8",
174            url: apiUrl+"app/bus/adv/common/addClickNum",
175            data: {
176                params:JSON.stringify({"advId":advId}),
177            },
178            success: function (result) {
179                if(result.code==100){
180                    console.log(link)
181                    if(linkType==1){
182                        layer.open({
183                            type: 1,
184                            title: false,
185                            area: ['900px', '510px'],
186                            shade: [0.8, 'rgb(14, 16, 22)'],
187                            skin: 'demo-class',
188                            content: '<video src="'+link+'" autoplay="true"  controls="controls" controlsList="nodownload noplaybackrate" disablePictureInPicture  style="width:900px;height:506px;"></video>'
189                        });
190
191                    }else{
192                        window.open(link);
193                    }
194
195                }
196            }, error: function (e) {
197            }
198        })
199    }
200}
201
202function imgerrorfun(isLive){
203    var img=event.srcElement;
204    if(isLive){
205        img.src="https://static.orangenews.hk/static/orange/img/zb-default.jpg";
206    }else{
207        img.src="https://static.orangenews.hk/static/orange/img/default.png";
208    }
209    img.onerror=null;
210}
211
212function replaceFilterTitle(title){
213    //去除两端非中英文数字的字符,偏僻字'丨'也去掉
214    title = title.replace(/^([^\u4e00-\u9fa5A-Za-z0-9]|丨)+|([^\u4e00-\u9fa5A-Za-z0-9]|丨)+$/g, "");
215
216    //匹配不是中文、英文大小写、数字的其他字符,都替换为-,偏僻字'丨'也替换掉
217    return title.replace(/[^\u4e00-\u9fa5a-zA-Z0-9]|[\u4E28]/g,"-");
218}
219
220// 内容页替换富文本图片alt 和 添加略缩图后缀
221function getImgSrc(richtext, filterTitle, flag,image_w960) {
222    const parser = new DOMParser();
223    const doc = parser.parseFromString(richtext, 'text/html');
224
225    const images = doc.getElementsByTagName('img');
226    const defaultImage = 'https://static.orangenews.hk/static/orange/img/default.png';
227    let a;
228    if(image_w960 == undefined){
229        image_w960 = 'x-oss-process=style/w960'
230        a = image_w960;
231    }else{
232        a = image_w960.substring(0,15)
233    }
234    for (let i = 0; i < images.length; i++) {
235        // 替换 alt
236        images[i].setAttribute('alt', filterTitle);
237        // 添加略缩图后缀
238        let src = images[i].getAttribute('src');
239        if(images[i].getAttribute('src').includes('cdn.orangenews.hk') && !(images[i].getAttribute('src').includes(a))) {
240            src = src + '?' + image_w960;
241            images[i].setAttribute('src', src);
242        }
243
244        if(!flag) {
245            // 替换为懒加载属性
246            images[i].setAttribute('data-original', src);
247            images[i].setAttribute('src', defaultImage);
248            images[i].classList.add('lazy');
249        }
250    }
251
252    return doc.documentElement.innerHTML;
253}
254
255// 視頻廣告
256function getVideoAd(url, id) {
257    return new Promise((resolve, reject) => {
258        $.ajax({
259            type: "POST",
260            dataType: "json",
261            headers: {
262                Authorization: localStorage.getItem("token")
263            },
264            contentType: "application/x-www-form-urlencoded;charset=UTF-8",
265            url: url + "app/bus/adv/common/getCommonAdv",
266            data: {
267                params: JSON.stringify({"advType": "0", "spaceType": "9", "targetId": `${id}`})
268            },
269            success: function (result) {
270                let videoAdvList_key = 'videoAdvList_'+id;
271                let videoAdvIndex_key = 'videoAdvIndex_'+id;
272                if (result.data.length > 0 && result.data.length) {
273                    // 处理视频广告数据
274                    let videoAdv;
275                    let videoAdvList = JSON.parse(localStorage.getItem(videoAdvList_key));
276                    let vaList = JSON.stringify(result.data);
277                    if (localStorage.getItem(videoAdvList_key) !== vaList) {
278                        videoAdv = result.data[0];
279                        localStorage.setItem(videoAdvList_key, vaList);
280                        localStorage.setItem(videoAdvIndex_key, 1);
281                    } else {
282                        let videoAdvIndex = localStorage.getItem(videoAdvIndex_key);
283                        if (videoAdvIndex == '' || videoAdvIndex == videoAdvList.length) {
284                            videoAdv = videoAdvList[0];
285                            localStorage.setItem(videoAdvIndex_key, 1);
286                        } else {
287                            videoAdv = videoAdvList[videoAdvIndex];
288                            localStorage.setItem(videoAdvIndex_key, parseInt(videoAdvIndex) + 1);
289                        }
290                    }
291                    // 构造视频广告组件对象
292                    let videoADComponent = {
293                        name: 'VideoADComponent',
294                        type: AliPlayerComponent.VideoADComponent,
295                        args: [videoAdv.image_url, videoAdv.image_link]
296                    };
297                    resolve(videoADComponent);
298                } else {
299                    localStorage.removeItem(videoAdvList_key);
300                    localStorage.removeItem(videoAdvIndex_key);
301                    reject("No video ad available");
302                }
303            },
304            error: function (e) {
305                reject(e);
306            }
307        });
308    });
309}
310
311// 一般详情页签发时间格式化
312function timeFormate(dt) {
313    let yy = dt.getFullYear();
314    let mm = dt.getMonth() + 1;
315    let dd = dt.getDate();
316    let hh = dt.getHours();
317    let mi = dt.getMinutes();
318    let ss = dt.getSeconds();
319    let dy = dt.getDay();
320    let wk = "週" + "日一二三四五六".charAt(dy);
321    let sd = "上午";
322    if (hh > 12) {
323        hh = hh - 12;
324        sd = "下午";
325    }
326    mi = mi < 10 ? "0" + mi : mi;
327
328    return yy + "年" + mm + "月" + dd + "日" + "   " + wk + "  " + sd + hh + ":" + mi;
329}
330
331// 防抖函数
332function debounce(func, wait) {
333    let timeoutId;
334    return function(...args) {
335        clearTimeout(timeoutId);
336        timeoutId = setTimeout(() => {
337            func.apply(this, args);
338        }, wait);
339    };
340}

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.