User:Irukaza/common.js:修订间差异

H萌娘,万物皆可H的百科全书!
跳到导航 跳到搜索
imported>=海豚=
无编辑摘要
imported>=海豚=
无编辑摘要
第1行: 第1行:
mw.loader.load('https://www.hmoegirl.com/index.php?title=User:=海豚=/js/userStatus.js&action=raw&ctype=text/javascript');
/* eslint-disable no-magic-numbers */
/* global mw */
"use strict";
"use strict";
$(() => (async () => {
$(() => (async () => {
    await mw.loader.using(["mw.Api", "mediawiki.Uri"]);
    await mw.loader.using(["mw.Api", "mediawiki.Uri"]);
    const groupsKey = ["bureaucrat", "sysop", "patroller", "goodeditor", "bot"].reverse();
    const groupsKey = ["bureaucrat", "checkuser", "suppress", "sysop", "patroller", "bot", "goodeditor"].reverse();
    const groupsStr = {
    const groupsStr = {
      bureaucrat: " ",
      bureaucrat: " 行",
     checkuser: "查",
     suppress: "监",
      sysop: "管",
      sysop: "管",
      patroller: "巡",
      patroller: "巡",
     bot: "机",
      goodeditor: "优",
      goodeditor: "优",
     bot: "机",
    };
    };
    let cache;
    let cache;
第19行: 第18行:
        || typeof cache.timestamp !== "number" || cache.timestamp < new Date().getTime() - 30 * 60 * 1000
        || typeof cache.timestamp !== "number" || cache.timestamp < new Date().getTime() - 30 * 60 * 1000
        || !$.isPlainObject(cache.groups)) {
        || !$.isPlainObject(cache.groups)) {
        cache = {};
        throw new Error();
      } else {
      } else {
        for (const i of groupsKey) {
        for (const i of groupsKey) {
          if (!Array.isArray(cache.groups[i])) {
          if (!Array.isArray(cache.groups[i])) {
            cache = {};
            throw new Error();
           break;
          }
          }
        }
        }
      }
      }
    } catch (e) {
    } catch {
      console.info("AnnTools-usergroup", e);
     const api = new mw.Api();
      cache = {};
     const result = {};
     const eol = Symbol();
      let aufrom = undefined;
     while (aufrom !== eol) {
       const _result = await api.post({
         action: "query",
         list: "allusers",
         augroup: groupsKey.join("|"),
         aulimit: "max",
         auprop: "groups",
         aufrom,
       });
       if (_result.continue) {
         aufrom = _result.continue.aufrom;
       } else {
         aufrom = eol;
       }
       _result.query.allusers.forEach(({
         name,
         groups,
       }) => {
         groups.forEach((group) => {
           if (groupsKey.includes(group)) {
             result[group] = result[group] || [];
             if (!result[group].includes(name)) {
               result[group].push(name);
             }
           }
         });
       });
     }
      cache = {
       timestamp: new Date().getTime(),
       groups: result,
     };
    }
    }
    localStorage.setItem("AnnTools-usergroup", JSON.stringify(cache));
    localStorage.setItem("AnnTools-usergroup", JSON.stringify(cache));
    if (!$.isPlainObject(cache.groups)) {
    const hook = () => {
     const api = new mw.Api();
     $("a.mw-userlink:not(.markrights)").each((_, ele) => {
     const result = await (async () => {
        ele.classList.add("markrights");
        const result = {};
        const uri = new mw.Uri(ele.href);
        const eol = Symbol();
        let username;
        let aufrom = undefined;
       const path = decodeURI(uri.path);
        while (aufrom !== eol) {
        if (/^\/User:[^/=%]+/.test(path)) {
          const _result = await api.post({
          username = path.match(/^\/User:([^/=%]+)/)[1].replace(/_/g, " ");
           action: "query",
       } else if (/^User:[^/=%]+/.test(uri.query.title)) {
           list: "allusers",
         username = uri.query.title.match(/^User:([^/=%]+)/)[1].replace(/_/g, " ");
           augroup: groupsKey.join("|"),
       }
           aulimit: "max",
       if (username) {
           auprop: "groups",
          const self = $(ele);
           aufrom,
         groupsKey.forEach((group) => {
         });
           if (cache.groups[group].includes(username)) {
         if (_result.continue) {
             self.after(`<sup class="markrights-${group}">${groupsStr[group]}<sup>`);
           aufrom = _result.continue.aufrom;
            }
         } else {
           aufrom = eol;
         }
         _result.query.allusers.forEach(({
           name,
           groups,
          }) => {
           groups.forEach((group) => {
             if (groupsKey.includes(group)) {
               result[group] = result[group] || [];
               if (!result[group].includes(name)) {
                 result[group].push(name);
               }
             }
            });
          });
          });
        }
        }
       return result;
      });
      })();
      for (const group of Object.keys(groupsStr)) {
      cache.timestamp = new Date().getTime();
       $(`.markrights-${group}`).nextUntil(':not([class*="markrights-"])').filter(`.markrights-${group}`).remove();
     cache.groups = result;
     localStorage.setItem("AnnTools-usergroup", JSON.stringify(cache));
   }
   $("a.mw-userlink").each((_, ele) => {
     const uri = new mw.Uri(ele.href);
     let username;
     const path = decodeURI(uri.path);
     if (/^\/User:[^/=%]+/.test(path)) {
       username = path.match(/^\/User:([^/=%]+)/)[1].replace(/_/g, " ");
     } else if (/^User:[^/=%]+/.test(uri.query.title)) {
       username = uri.query.title.match(/^User:([^/=%]+)/)[1].replace(/_/g, " ");
      }
      }
     if (username) {
   };
       const self = $(ele);
   hook();
       groupsKey.forEach((group) => {
   mw.hook("wikipage.content").add(hook);
         if (cache.groups[group].includes(username)) {
   $(window).on("load", hook);
           self.after(`<sup class="markrights-${group}">${groupsStr[group]}<sup>`);
    $("body").append("<style>.markrights-bureaucrat{color:black}.markrights-checkuser{color:purple}.markrights-suppress{color:purple}.markrights-sysop{color:mediumvioletred}.markrights-patroller{color:sienna}.markrights-bot{color:blue}.markrights-goodeditor{color:green}sup[class^=markrights-]+sup[class^=markrights-]{margin-left:2px}</style>");
         }
       });
     }
   });
    $("body").append("<style>.markrights-bureaucrat{color:#66CCFF}.markrights-sysop{color:#FF7F50}.markrights-patroller{color:#DA70D6}.markrights-goodeditor{color:#FFB6C1}.markrights-bot{color:#40E0D0}sup[class^=markrights]+sup[class^=markrights]{margin-left:2px}</style>");
})());
})());
//改自对A姐,删除了萌百不必要显示的职位,修改了颜色。

2021年3月23日 (二) 21:31的版本

"use strict";
$(() => (async () => {
    await mw.loader.using(["mw.Api", "mediawiki.Uri"]);
    const groupsKey = ["bureaucrat", "checkuser", "suppress", "sysop", "patroller", "bot", "goodeditor"].reverse();
    const groupsStr = {
        bureaucrat: "行",
        checkuser: "查",
        suppress: "监",
        sysop: "管",
        patroller: "巡",
        bot: "机",
        goodeditor: "优",
    };
    let cache;
    try {
        cache = JSON.parse(localStorage.getItem("AnnTools-usergroup"));
        if (!$.isPlainObject(cache)
            || typeof cache.timestamp !== "number" || cache.timestamp < new Date().getTime() - 30 * 60 * 1000
            || !$.isPlainObject(cache.groups)) {
            throw new Error();
        } else {
            for (const i of groupsKey) {
                if (!Array.isArray(cache.groups[i])) {
                    throw new Error();
                }
            }
        }
    } catch {
        const api = new mw.Api();
        const result = {};
        const eol = Symbol();
        let aufrom = undefined;
        while (aufrom !== eol) {
            const _result = await api.post({
                action: "query",
                list: "allusers",
                augroup: groupsKey.join("|"),
                aulimit: "max",
                auprop: "groups",
                aufrom,
            });
            if (_result.continue) {
                aufrom = _result.continue.aufrom;
            } else {
                aufrom = eol;
            }
            _result.query.allusers.forEach(({
                name,
                groups,
            }) => {
                groups.forEach((group) => {
                    if (groupsKey.includes(group)) {
                        result[group] = result[group] || [];
                        if (!result[group].includes(name)) {
                            result[group].push(name);
                        }
                    }
                });
            });
        }
        cache = {
            timestamp: new Date().getTime(),
            groups: result,
        };
    }
    localStorage.setItem("AnnTools-usergroup", JSON.stringify(cache));
    const hook = () => {
        $("a.mw-userlink:not(.markrights)").each((_, ele) => {
            ele.classList.add("markrights");
            const uri = new mw.Uri(ele.href);
            let username;
            const path = decodeURI(uri.path);
            if (/^\/User:[^/=%]+/.test(path)) {
                username = path.match(/^\/User:([^/=%]+)/)[1].replace(/_/g, " ");
            } else if (/^User:[^/=%]+/.test(uri.query.title)) {
                username = uri.query.title.match(/^User:([^/=%]+)/)[1].replace(/_/g, " ");
            }
            if (username) {
                const self = $(ele);
                groupsKey.forEach((group) => {
                    if (cache.groups[group].includes(username)) {
                        self.after(`<sup class="markrights-${group}">${groupsStr[group]}<sup>`);
                    }
                });
            }
        });
        for (const group of Object.keys(groupsStr)) {
            $(`.markrights-${group}`).nextUntil(':not([class*="markrights-"])').filter(`.markrights-${group}`).remove();
        }
    };
    hook();
    mw.hook("wikipage.content").add(hook);
    $(window).on("load", hook);
    $("body").append("<style>.markrights-bureaucrat{color:black}.markrights-checkuser{color:purple}.markrights-suppress{color:purple}.markrights-sysop{color:mediumvioletred}.markrights-patroller{color:sienna}.markrights-bot{color:blue}.markrights-goodeditor{color:green}sup[class^=markrights-]+sup[class^=markrights-]{margin-left:2px}</style>");
})());