PageSourceSearch

http://www.chemnanotopology.com/js/jiaogeiwocommon.js

js chemnanotopology.com collected 2026-10-06 13:59:49 UTC 6,028 bytes, 163 lines download raw bytes

1/**
2 * 默认跳转到指定语言
3 * 默认调整到英文: jumpLang('en');
4 * 
5 */
6function jumpLang(lang) {
7    // 只有直接访问域名才用
8    if (location.pathname === '/') {
9        location.href = '/' + lang;
10    }
11}
12
13/**
14 * 手机端显示pc端网页
15 */
16 function browserRedirect() {
17    var sUserAgent = navigator.userAgent.toLowerCase();
18    var bIsIpad = sUserAgent.match(/ipad/i) == "ipad";
19    var bIsIphoneOs = sUserAgent.match(/iphone os/i) == "iphone os";
20    var bIsMidp = sUserAgent.match(/midp/i) == "midp";
21    var bIsUc7 = sUserAgent.match(/rv:1.2.3.4/i) == "rv:1.2.3.4";
22    var bIsUc = sUserAgent.match(/ucweb/i) == "ucweb";
23    var bIsAndroid = sUserAgent.match(/android/i) == "android";
24    var bIsCE = sUserAgent.match(/windows ce/i) == "windows ce";
25    var bIsWM = sUserAgent.match(/windows mobile/i) == "windows mobile";
26
27    if (bIsIpad || bIsIphoneOs || bIsMidp || bIsUc7 || bIsUc || bIsAndroid || bIsCE || bIsWM) {
28        // window.location.href = 'm' + location.pathname + location.search;
29        document.querySelector('head').innerHTML += '<meta name="viewport" content="width=1200px, initial-scale=0.3">'
30    }
31}
32
33/**
34 * 显示文章、产品模块的移动端详情字段
35 */
36function showMContent(m_content_url) {
37    return `${m_content_url ? `<script src="//cdn.xuansiwei.com/${m_content_url}.js"></script>` : ''}`;
38}
39
40/**
41 * 文章、产品详情实现图片异步加载
42 */
43function laodLazyPcContent(pc_content_url) {
44    return `
45        <div class="pc_content"></div>
46        <script>
47            $.ajax({
48                url: '//cdn.xuansiwei.com/${pc_content_url}.txt', 
49                async: false, 
50                success: function(txt){
51                    var content = txt.replace(/src="(.+?)"/g, (word, a) => \`src="data:image/gif;base64,R0lGODdhAQABAPAAAMPDwwAAACwAAAAAAQABAAACAkQBADs=" data-src="\${a}" style="max-width: 100%; min-height: 200px"\`);
52                    $('.pc_content').html(content);
53                }
54            });
55        </script>
56    `
57}
58
59/**
60 * 网站是否被嵌在iframe中
61 */
62function isIframe() {
63    return self !== top;
64}
65
66/**
67 * 301重定向
68 */
69function redirectToWWW() {
70    if (location.hostname.split('.').length === 2) {
71        location.href = location.protocol + '//www.' + location.host + location.pathname;
72    }
73}
74
75/**
76 * 屏蔽中国ip代码
77 */
78function shieldChina() {
79    if (location.host.indexOf('caihongjianzhan.com') === -1) { // 只有正式域名才执行
80        fetch('//yun-api.sungdell.com/ip-country')
81            .then(res => res.json())
82            .then(res => {
83                if (res.country === 'CN') {
84                    location.href = "cnlogin.html";
85                }
86            })
87    }
88}
89
90/**
91 * 禁止页面复制
92 */
93function banCopy() {
94    document.writeln(`
95        <script>  
96            document.oncontextmenu=new Function("event.returnValue=false");  
97            document.onselectstart=new Function("event.returnValue=false");  
98        </script> 
99    `);
100}
101
102/**
103 * 用图片主色作为背景渐变
104 */
105 function setSectionsMainColor(imgEle) {
106    imgEle.crossOrigin = "Anonymous";
107    if (imgEle.naturalWidth === 0) {
108        console.info('naturalWidth is 0');
109        return;
110    }
111    const canvas = document.createElement('canvas')
112    var ctx = canvas.getContext("2d");
113    var naturalImgSize = [imgEle.naturalWidth, imgEle.naturalHeight];
114    canvas.width = naturalImgSize[0];
115    canvas.height = naturalImgSize[1];
116    
117    //绘制到canvas
118    ctx.drawImage(imgEle, 0, 0);
119    //获取imageData:rgba像素点
120    var imgData = ctx.getImageData(0, 0, canvas.width, canvas.height);
121    const leftSectionData = []
122    const rightSectionData = []
123    const onelineImgDataLen = canvas.width * 4;
124
125    imgData.data.forEach((colorVal, i) => {
126        if (i % onelineImgDataLen <= 0.5 * onelineImgDataLen || i % onelineImgDataLen >= 0.6 * onelineImgDataLen) {
127            const inLeft = i % onelineImgDataLen <= 0.5 * onelineImgDataLen
128            if (i % 4 === 0) {
129                // 获取rgb均值
130                const curAverageRGB = (imgData.data[i] + imgData.data[i + 1] + imgData.data[i + 2]) / 3;
131                let leftOrRightRef = inLeft ? leftSectionData : rightSectionData;
132                //每个数组里存四个值:本颜色值中的r、g、b的均值,以及r、g、b三个值。
133                //均值一方面用于累加计算本区域的整体均值,然后再跟每个均值对比拿到与整体均值最接近的项的索引,再取该数组里的后三个值:rgb,对应着颜色
134                leftOrRightRef[leftOrRightRef.length] = [curAverageRGB, imgData.data[i], imgData.data[i + 1], imgData.data[i + 2]]
135            }
136        }
137    })
138    //generate average rgb
139    const averageOfLeft = Math.round(leftSectionData.reduce((_cur, item) => {
140        return _cur + item[0]
141    }, 0) / leftSectionData.length)
142    const averageOfRight = Math.round(rightSectionData.reduce((_cur, item) => {
143        return _cur + item[0]
144    }, 0) / rightSectionData.length)
145    //find the most near color
146    const findNearestIndex = (averageVal, arrBox) => {
147        let _gapValue = Math.abs(averageVal - arrBox[0])
148        let _nearColorIndex = 0
149        arrBox.forEach((item, index) => {
150            const curGapValue = Math.abs(item - averageVal)
151            if (curGapValue < _gapValue) {
152                _gapValue = curGapValue
153                _nearColorIndex = index
154            }
155        })
156        return _nearColorIndex
157    }
158
159    const leftNearestColor = leftSectionData[findNearestIndex(averageOfLeft, leftSectionData)]
160    const rightNearestColor = rightSectionData[findNearestIndex(averageOfRight, rightSectionData)]
161    console.log(leftNearestColor,rightNearestColor);
162    $(imgEle).parent().css('background-image', 'linear-gradient(90deg,rgba(' + leftNearestColor[1] + ',' + leftNearestColor[2] + ',' + leftNearestColor[3] + ',1) 0%,rgba(' + rightNearestColor[1] + ',' + rightNearestColor[2] + ',' + rightNearestColor[3] + ',1) 100%')
163}

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.