PageSourceSearch

https://nj.lizhi.fm/assets/js/lizhi_nj/0e2b70c72ac3a4c9fe6b32f57c5a6df0-grayVersion.js

js lizhi.fm collected 2026-10-02 03:24:09 UTC 3,934 bytes, 130 lines download raw bytes

1;(function () {
2  function checkSession(key) {
3    var version = sessionStorage.getItem(key)
4    if (version === null) {
5      return false
6    } else {
7      return version + ""
8    }
9  }
10
11  function getUrl() {
12    var reg = /(nj)(.*\.(lizhi(\.fm|fm\.com)|lz310\.com))/
13    var hostname = window.location.hostname
14    return "//" + hostname.replace(reg, "$1new$2") + "/user/getGrayVersion"
15  }
16
17  // 设置css
18  function injectStyle(version) {
19    // 1期灰度样式
20    let styleContent = '.rebuild-grey-hide{display: none !important;}.rebuild-grey-show{display: block !important;}'
21    // 2期灰度样式
22    if (version && Number(version) >= 2) {
23      styleContent += '.rebuild-grey-hide2{display: none !important;}.rebuild-grey-show2{display: block !important;}'
24    }
25    $("head").append(
26      '<style type="text/css">' + styleContent + '</style>'
27    )
28  }
29
30  function backToNewSite() {
31    console.log("backToNewSite trigger")
32    var fromNew = sessionStorage.getItem("fromNew") || "/index"
33    sessionStorage.removeItem("fromNew")
34    window.location.href =
35      "/static/newsite/index.html#" + fromNew + "?fromOld=true"
36  }
37
38  function bindBackHandler() {
39    $(document).on("click", function (e) {
40      var target = e.target
41      if (target.id === "backToNew") {
42        backToNewSite()
43      } else if (target.className === "homeLogo") {
44        window.location.href = window.NJ_HOME_PAGE_URL || "/"
45      }
46    })
47  }
48  function getSearchParam(key) {
49    return (new RegExp('[?&]' + key + '=([^&]+)').exec(window.location.search) ||
50      [])[1]
51  }
52
53  function checkUrl() {
54    var newSiteRoute = getSearchParam("fromNew")
55    if (newSiteRoute) {
56      sessionStorage.setItem("fromNew", decodeURIComponent(newSiteRoute))
57    }
58  }
59
60  function __main() {
61    /**
62     * 1. 检查sessionStorage中有没有灰度标识
63     * 2. 有标识根据标识判断 灰度用户插入css样式
64     * 3. 没有标识 请求灰度接口 写入sessionStorage
65     * 4. 检查url上有没有fromNew, 将来的路由存到sessionStorage中
66     */
67    // 设置全局 灰度标识
68    Object.defineProperty(window, "targetVersion", {
69      value: 1,
70      configurable: false,
71      writable: false,
72      enumerable: false,
73    })
74
75    checkUrl()
76    var sessionKey = "rebuildGreyVersion"
77    var version = checkSession(sessionKey)
78    if (version) {
79      if (Number(version) >= targetVersion) {
80        // 命中灰度 插入css
81
82        injectStyle(version)
83        bindBackHandler()
84        // 设置全局 首页URL
85        Object.defineProperty(window, "NJ_HOME_PAGE_URL", {
86          value: "/static/newsite/",
87          configurable: false,
88          writable: false,
89          enumerable: false,
90        })
91        if (location.pathname === "/") {
92          window.location.href = window.NJ_HOME_PAGE_URL
93        }
94      }
95    } else {
96      // 没有标识 且 非登录页 请求接口
97      if (!(window.location.pathname.indexOf("account/login") > -1)) {
98        $.ajax({
99          url: getUrl(),
100          xhrFields: {
101            withCredentials: true,
102          },
103          success: function (res) {
104            console.log("success", res)
105            if (res.rcode === 0) {
106              var version = res.data.version
107              sessionStorage.setItem(sessionKey, version)
108              if (Number(version) >= targetVersion) {
109                injectStyle(version)
110                bindBackHandler()
111                // 设置全局 首页URL
112                Object.defineProperty(window, "NJ_HOME_PAGE_URL", {
113                  value: "/static/newsite/",
114                  configurable: false,
115                  writable: false,
116                  enumerable: false,
117                })
118                if (location.pathname === "/") {
119                  window.location.href = window.NJ_HOME_PAGE_URL
120                }
121              }
122            }
123          },
124        })
125      }
126    }
127  }
128
129  __main()
130})()

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.