PageSourceSearch

https://olto3-sugi3.tk/common.js

js olto3-sugi3.tk collected 2026-09-24 15:12:32 UTC 16,016 bytes, 477 lines download raw bytes

1function setUserInfo(myJson){
2    let TAG = "common.js:setUserInfo";
3    logging("debug", TAG, "start");
4    LOGIN={};
5    if ("userinfo" in myJson){
6        LOGIN = myJson["userinfo"];
7    } else {
8        //ログインが無効だったら初期画面に移動
9        let next = "/login/login.html";
10        if( typeof ANDROID === 'undefined'){
11            // do nothing
12        } else if (ANDROID == "true") {
13            next = "/login/ANDROID.html";
14        }
15        $("#messageArea").text(JSON.stringify(myJson));
16        let myError = myJson["error"];
17        if (typeof myError == "object") {
18            if ("code" in myError && "message" in myError) {
19                $("#messageArea").text(myError["code"] + ":" + myError["message"]);
20            }
21        }
22        logging("ERROR", TAG, JSON.stringify(myJson));
23        AlertDialogNext(STRINGS["login_failed"], "warning", next)
24        return false;
25    }
26    if ("workspace" in myJson){
27        LOGIN["workspace"] = myJson["workspace"];
28        if ("lang" in myJson["workspace"]){
29            LANG = myJson["workspace"]["lang"]
30            $.cookie("LANG", LANG, { "path": MYROOT, "expires": 7, "secure":true });
31        }
32    }
33    if( typeof LANG === 'undefined'){
34        logging("debug", TAG, "get LANG from navigator");
35        // 最優先の言語だけ取得
36        let lcid = ((window.navigator.languages && window.navigator.languages[0]) ||
37                    window.navigator.language ||
38                    window.navigator.userLanguage ||
39                    window.navigator.browserLanguage).split('-');
40        if (typeof lcid == 'undefined'){
41            LANG = 'en'
42        } else if (lcid instanceof Array) {
43            if (lcid[0] == "") {
44                LANG = 'en'
45            } else {
46                LANG = lcid[0]
47            }
48        } else {
49            LANG = 'en'
50        }
51    }
52    $.cookie("LOGIN", JSON.stringify(LOGIN), { "path": MYROOT, "secure":true }); //セッションクッキー
53    return true;
54}
55
56function logout(){
57    let TAG = "common.js:logout";
58    logging("debug", TAG, "start");
59    $.removeCookie("refreshToken", { "path": MYROOT , "secure":true});
60    $.removeCookie("LANG", { "path": MYROOT , "secure":true});
61    $.removeCookie("LOGIN", { "path": MYROOT , "secure":true});
62    ANDROID = $.cookie("ANDROID"); //セッションクッキー
63    let obj = {method:"revoke_tokens"};
64    $("#loading").fadeIn();
65    getPython("/cgi-bin/common/login.py", obj).then(myJson=>{
66        $("#loading").fadeOut();
67        if ("error" in myJson) {
68            logging("error", TAG, JSON.stringify(myJson));
69        } else {
70            //do nothing
71        }
72        if (location.pathname == MYROOT + '/login/login.html') {
73            //do nothing ありえないパターン
74        } else if (typeof ANDROID === 'undefined'){
75            logging("debug",TAG,"main onload : goto login.html : " + location.pathname)
76            //AlertDialogNext("logout",'information',"/login/login.html")
77            location.href = MYROOT + "/login/login.html";
78        } else if (ANDROID == "true") {
79            logging("debug",TAG, "main onload : ANDROID.html : " + location.pathname)
80            //AlertDialogNext("logout",'information',"/login/ANDROID.html")
81            location.href = MYROOT + "/login/ANDROID.html";
82        } else {
83            //念のため
84            logging("debug",TAG, "main onload : goto login.html : " + location.pathname)
85            //AlertDialogNext("logout",'information',"/login/login.html")
86            location.href = MYROOT + "/login/login.html";
87        }
88    });
89}
90function YMDHHMMSSm(myDate){
91    let strTime = YYYYMMDD(myDate);
92    strTime += "-";
93    let num = myDate.getHours();
94    if (num < 10) {
95        strTime += "0";
96    }
97    strTime += num;
98    strTime += ":";
99    num = myDate.getMinutes();
100    if (num < 10) {
101        strTime += "0";
102    }
103    strTime += num;
104    strTime += ":";
105    num = myDate.getSeconds();
106    if (num < 10) {
107        strTime += "0";
108    }
109    strTime += num;
110    strTime += ".";
111    strTime += myDate.getMilliseconds();
112    return strTime
113}
114function YYYYMMDD(myDate){
115    let strDate = String(myDate.getFullYear())
116    strDate += "-"
117    let num = myDate.getMonth() + 1;
118    if (num < 10) {
119        strDate += "0";
120    }
121    strDate += num
122    strDate += "-"
123    num = myDate.getDate();
124    if (num < 10) {
125        strDate += "0";
126    }
127    strDate += num;
128    return strDate
129}
130function YYYYMM(myDate){
131    let strDate = String(myDate.getFullYear())
132    strDate += "-"
133    let num = myDate.getMonth() + 1;
134    if (num < 10) {
135        strDate += "0";
136    }
137    strDate += num
138    return strDate
139}
140function HHMMSS(myDate){
141    let strTime = "";
142    let num = myDate.getHours();
143    if (num < 10) {
144        strTime += "0";
145    }
146    strTime += num
147    strTime += ":"
148    num = myDate.getMinutes();
149    if (num < 10) {
150        strTime += "0";
151    }
152    strTime += num
153    strTime += ":"
154    num = myDate.getSeconds();
155    if (num < 10) {
156        strTime += "0";
157    }
158    strTime += num;
159    return strTime;
160}
161function HHMM00(myDate){
162    // 秒を切り捨てる前に一分加算する
163    myDate.setSeconds( myDate.getSeconds() + 60 );
164    let strTime = "";
165    let num = myDate.getHours();
166    if (num < 10) {
167        strTime += "0";
168    }
169    strTime += num
170    strTime += ":"
171    num = myDate.getMinutes();
172    if (num < 10) {
173        strTime += "0";
174    }
175    strTime += num
176    // 秒はいらない
177    return strTime;
178}
179
180function showOsano(){
181    let TAG = "common.js:showOsano";
182    logging("debug", TAG, "start");
183    Osano.cm.showDrawer('osano-cm-dom-info-dialog-open')
184}
185
186function AlertDialogNext(strComment, level ,next) {
187    let TAG = "common.js:AlertDialogNext";
188    logging("debug", TAG, "start");
189    // <div id="showdialog"></div> がhtmlのbodyの1階層目に無いと出ない
190    let myNext = next;
191    if (next == "/login/login.html") {
192        ANDROID = $.cookie("ANDROID"); //セッションクッキー
193        if (typeof ANDROID === 'undefined') {
194            //do nothing
195        } else if (ANDROID == "true") {
196            myNext = "/login/ANDROID.html";
197        } else {
198            //do nothing
199        }
200    }
201    let myTitle = level;
202    if (typeof STRINGS === 'undefined') {
203        // do nothing
204    } else {
205        myTitle = STRINGS[level];
206    }
207    $( "#showdialog" ).html(strComment).dialog({
208        dialogClass: level,
209        modal: true,
210        title: myTitle,
211        buttons: {
212            "OK": function() {
213                $( this ).dialog( "close" );
214                location.href =  MYROOT + myNext;
215            }
216        }
217    });
218}
219
220function AlertDialogBack(strComment, level){
221    let TAG = "common.js:AlertDialog";
222    logging("debug", TAG, "start");
223    // <div id="showdialog"></div> がhtmlのbodyの1階層目に無いと出ない
224    let myTitle = level;
225    if (typeof STRINGS === 'undefined') {
226        //do nothing
227    } else {
228        myTitle = STRINGS[level];
229    }
230    $( "#showdialog" ).html(strComment).dialog({
231        dialogClass: level,
232        modal: true,
233        title: myTitle,
234        buttons: {
235            "OK": function() {
236                $( this ).dialog( "close" );
237                history.back();
238            }
239        }
240    });
241}
242
243function AlertDialog(strComment, level) {
244    let TAG = "common.js:AlertDialog";
245    logging("debug", TAG, "start");
246    // <div id="showdialog"></div> がhtmlのbodyの1階層目に無いと出ない
247    let myTitle = level;
248    if (typeof STRINGS === 'undefined') {
249        //do nothing
250    } else {
251        myTitle = STRINGS[level];
252    }
253    $( "#showdialog" ).html(strComment).dialog({
254        dialogClass: level,
255        modal: true,
256        title: myTitle,
257        buttons: {
258            "OK": function() {
259                $( this ).dialog( "close" );
260            }
261        }
262    });
263}
264
265function setSTRINGS(){
266    let TAG = "common.js:setSTRINGS";
267    logging("debug", TAG, "start");
268    STRINGS = {};
269    // 各エレメントに、言語ごとの文字列をセット
270    $.getJSON( MYROOT + "/res/" + LANG + "/strings.json").then(
271        //非同期で実行される
272        (...args) => { // done
273            let [strJson, textStatus, XMLHttpRequest] = args;
274            for(key in strJson){
275                let ELEMENTS = document.getElementsByName(key);
276                for(element of ELEMENTS) {
277                    element.innerHTML = strJson[key];
278                };
279            };
280            document.documentElement.lang = LANG;
281            STRINGS = strJson;
282        },
283        (...args) => { // fail
284            let [XMLHttpRequest, textStatus, errorThrown] = args;
285            $.getJSON( MYROOT + "/res/strings.json").then(strJson=>{
286                for(key in strJson){
287                    let ELEMENTS = document.getElementsByName(key);
288                    for(element of ELEMENTS) {
289                        element.innerHTML = strJson[key];
290                    };
291                };
292                document.documentElement.lang = "en";
293                STRINGS = strJson;
294            });
295        }
296    );
297    return STRINGS;
298}
299
300function getPython(url, obj){
301    let TAG = "common.js:getPython";
302    logging("debug", TAG, "start: url:" + url + "obj:" + JSON.stringify(obj));
303    if (location.hostname == 'test.local.olto3-sugi3.tk'){
304        logging("debug",TAG, "getPython : Local test ");
305        let testjson="/localtest/" + obj.method + ".json"
306        if ("collection" in obj) {
307            if ((obj.method == "get_all") || (obj.method == "get_query") || (obj.method == "get_2_query")
308            || (obj.method == "get_mine")) {
309                testjson="/localtest/" + obj.collection + ".json"
310            }
311        }
312        // testjson="/localtest/error.json"
313        return $.getJSON(testjson).then(result => {
314            return result;
315        });
316    } else {
317        obj['app_id'] = MYAPPLICATION;
318        return $.ajax({
319            type:"POST",                // method = "POST"
320            url:url,        // POST送信先のURL
321            contentType: 'application/json', // リクエストの Content-Type
322            data:JSON.stringify(obj)  // JSONデータ本体
323        }).then(
324            (...args) => { // done
325                let [result, textStatus, XMLHttpRequest] = args;
326                if (XMLHttpRequest.status==200){
327                    logging("debug",TAG, "getPython : run on Server");
328                    return result;
329                } else {
330                    logging("ERROR",TAG, "getPython(done) :");
331                    logging("ERROR",TAG, XMLHttpRequest);
332                    logging("ERROR",TAG, result);
333                    let myJson = {"error":{"code":XMLHttpRequest.status, "message":'"' + textStatus + '"'} };
334                    $("#messageArea").html("getPython(done):" + myJson["error"]["code"] + ":" + myJson["error"]["message"] + JSON.stringify(obj));
335                    return myJson;
336                }
337            } ,
338            (...args) => { // fail
339                let [XMLHttpRequest, textStatus, errorThrown] = args;
340                logging("ERROR" ,TAG, "getPython(fail) :");
341                //logging("ERROR" ,TAG, XMLHttpRequest.responseText);
342                logging("ERROR" ,TAG, errorThrown);
343                let myJson = {"error":{"code":XMLHttpRequest.status, "message":'"' + textStatus + ' : ' + errorThrown.message + '"'} };
344                $("#messageArea").html("getPython(fail):" + myJson["error"]["code"] + ":" + myJson["error"]["message"] + ":" + JSON.stringify(obj));
345                return myJson;
346            }
347        );
348    }
349}
350function set_mailtoUi(){
351    let TAG = "common.js:set_mailtoUi";
352    logging("debug", TAG, "start");
353    if(/chrom(e|ium)/.test(navigator.userAgent.toLowerCase())){
354        //chrome の時だけ実行
355        fetch("https://cdn.jsdelivr.net/npm/[email protected]/dist/mailtoui-min.js").then(res=>{
356            return res.text();
357        }).then(mtext => {
358            eval(mtext);
359        });
360    }
361}
362
363let mypath = location.pathname.split("/");
364if (mypath[1].match(/.html/)){
365    MYROOT = "";
366} else if (mypath[1] == "") {
367    MYROOT = "";
368} else {
369    if (mypath[1] == 'OLTO3-SUGI3'){
370        if (mypath[2] == ""){
371            MYROOT = "/" + mypath[1];
372        } else if (mypath[2].match(/.html/)){
373            MYROOT = "/" + mypath[1];
374        } else {
375            MYROOT = "/" + mypath[1] + "/" + mypath[2];
376        }
377    } else {
378        MYROOT = "/" + mypath[1];
379    }
380}
381if (location.hostname == 'test.local.olto3-sugi3.tk'){    
382    logging("debug", "common.js", "Local test " + MYROOT);
383} else {
384    logging("debug", "common.js", "run on server " + MYROOT);
385}
386
387$(function(){
388    // main の高さをフッターが最下部になるように調整
389    let windowHeight = $(window).height();
390    let headerHeight = $("header").outerHeight();
391    let footerHeight = $("footer").outerHeight();
392    $("main").css('min-height', windowHeight - headerHeight - footerHeight + 'px');
393})
394
395// console.log をサーバーに転送
396function logging(level, TAG, message){
397    let logmode = false;
398    if (typeof LOGIN == "undefined") {
399        logmode = false;
400    } else if ("workspace" in LOGIN) {
401        if ("logmode" in LOGIN["workspace"]) {
402            if (LOGIN["workspace"]["logmode"]) {
403                logmode = true;
404            } else {
405                logmode = false;
406            }
407        }
408    } else if ("custom_claims" in LOGIN) {
409        if ("logmode" in LOGIN["custom_claims"]) {
410            if (LOGIN["custom_claims"]["logmode"]) {
411                logmode = true;
412            } else {
413                logmode = false;
414            }
415        }
416    }
417    
418    let server = false;
419    if (location.hostname == 'test.local.olto3-sugi3.tk'){
420        server = false;
421    } else if (level == "ERROR") {
422        server = true;
423    } else if (logmode) {
424        server = true;
425    } else if (location.hostname == 'test.local.olto3-sugi3.tk'){
426        if (typeof ANDROID == "undefined") {
427            server = false;
428        } else if (ANDROID) {
429            server = true;
430        }
431    } else {
432        server = false;
433    }
434    console.log(level + ": " + TAG + ": " + message);
435    if (server) {
436        let pathname = location.pathname;
437        let plafrorm = navigator.platform;
438        let userAgent = navigator.userAgent;
439        let log_time = YMDHHMMSSm(new Date());
440        let email = "[email protected]";
441        let myserver = location.hostname;
442        if (typeof LOGIN == "undefined") {
443            email = "[email protected]";
444        } else if ("email" in LOGIN) {
445            email = LOGIN["email"]
446        } else {
447            email = "[email protected]";
448        }
449        let console_log = {"level":level, "TAG":TAG, "message":message, "server":myserver ,"pathname":pathname, "plafrorm":plafrorm, "userAgent":userAgent, "log_time":log_time, "email":email}
450        if (typeof MYAPPLICATION == "undefined") {
451            console_log["app_id"] = "MYAPPLICATION is undefined";
452        } else {
453            console_log["app_id"] = MYAPPLICATION;
454        }
455        let obj = {"method":"sendmail", "subject":log_time, "from":email, "data":JSON.stringify(console_log)};
456        $.ajax({
457            type:"POST",                // method = "POST"
458            url:"/cgi-bin/common/savelog.py",        // POST送信先のURL
459            contentType: 'application/json', // リクエストの Content-Type
460            data:JSON.stringify(obj)  // JSONデータ本体
461        }).then(myJson=>{
462            if ("error" in myJson) {
463                console.log(JSON.stringify(myJson));
464            }
465        });
466    } else {
467    }
468}
469function go2privacy(){
470    let TAG = "index.js:go2privacy";
471    logging("debug", TAG, "start");
472    if (LANG == "ja") {
473        window.open("https://www.olto3-sugi3.tk/privacy-policy/ja/index.html", '_blank')
474    } else {
475        window.open("https://www.olto3-sugi3.tk/privacy-policy/index.html", '_blank')
476    }
477}

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.