Greasy Fork

Greasy Fork is available in English.

NGA Agent

非常时期的非常手段

当前为 2022-10-06 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name        NGA Agent
// @namespace   http://greasyfork.icu/users/263018
// @version     1.2.4
// @author      snyssss
// @description 非常时期的非常手段
// @license     MIT

// @match       *://bbs.nga.cn/*
// @match       *://ngabbs.com/*
// @match       *://nga.178.com/*

// @noframes
// ==/UserScript==

(({ commonui: ui }) => {
  !function(t,r){for(var n in r)t[n]=r[n]}(window,function(t){function r(e){if(n[e])return n[e].exports;var o=n[e]={i:e,l:!1,exports:{}};return t[e].call(o.exports,o,o.exports,r),o.l=!0,o.exports}var n={};return r.m=t,r.c=n,r.i=function(t){return t},r.d=function(t,n,e){r.o(t,n)||Object.defineProperty(t,n,{configurable:!1,enumerable:!0,get:e})},r.n=function(t){var n=t&&t.__esModule?function(){return t.default}:function(){return t};return r.d(n,"a",n),n},r.o=function(t,r){return Object.prototype.hasOwnProperty.call(t,r)},r.p="",r(r.s=2)}([function(t,r,n){"use strict";function e(t,r){var n={};for(var e in t)n[e]=t[e];return n.target=n.currentTarget=r,n}function o(t,r){function n(r){return function(){var n=this.hasOwnProperty(r+"_")?this[r+"_"]:this.xhr[r],e=(t[r]||{}).getter;return e&&e(n,this)||n}}function o(r){return function(n){var o=this.xhr,i=this,u=t[r];if("on"===r.substring(0,2))i[r+"_"]=n,o[r]=function(u){u=e(u,i),t[r]&&t[r].call(i,o,u)||n.call(i,u)};else{var c=(u||{}).setter;n=c&&c(n,i)||n,this[r+"_"]=n;try{o[r]=n}catch(t){}}}}function i(r){return function(){var n=[].slice.call(arguments);if(t[r]){var e=t[r].call(this,n,this.xhr);if(e)return e}return this.xhr[r].apply(this.xhr,n)}}return r=r||window,r[c]=r[c]||r.XMLHttpRequest,r.XMLHttpRequest=function(){for(var t=new r[c],e=0;e<a.length;++e){var f="on"+a[e];void 0===t[f]&&(t[f]=null)}for(var s in t){var l="";try{l=u(t[s])}catch(t){}"function"===l?this[s]=i(s):Object.defineProperty(this,s,{get:n(s),set:o(s),enumerable:!0})}var h=this;t.getProxy=function(){return h},this.xhr=t},Object.assign(r.XMLHttpRequest,{UNSENT:0,OPENED:1,HEADERS_RECEIVED:2,LOADING:3,DONE:4}),r[c]}function i(t){t=t||window,t[c]&&(t.XMLHttpRequest=t[c]),t[c]=void 0}Object.defineProperty(r,"__esModule",{value:!0});var u="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t};r.configEvent=e,r.hook=o,r.unHook=i;var c="__xhr",a=r.events=["load","loadend","timeout","error","readystatechange","abort"]},,function(t,r,n){"use strict";Object.defineProperty(r,"__esModule",{value:!0}),r.ah=void 0;var e=n(0);r.ah={hook:e.hook,unHook:e.unHook}}]));
  //# sourceMappingURL=ajaxhook.core.min.js.map

  // User Agent
  const USER_AGENT = "Nga_Official/80024(Android12)";

  // RedirectUri
  const redirectUri = (() => {
    const params = new URLSearchParams(location.search);

    return params.get("redirectUri");
  })();

  // Skip
  if (!document.title) {
    return;
  }

  // Hook
  const hooked = (() => {
    if (location.pathname === "/") {
      ah.hook(
        {
          open: (args, xhr) => {
            xhr._url = args[1];

            return false;
          },
          send: (_, xhr) => {
            const url = xhr._url || "";

            if (url.indexOf("/") === 0 || url.indexOf(location.host) >= 0) {
              xhr.setRequestHeader("X-User-Agent", USER_AGENT);
            }

            return false;
          },
        },
        ui._w
      );

      const f = __NUKE.doRequest;

      __NUKE.doRequest = (args) => {
        if (args.u.a) {
          return f(args);
        }

        return f({
          ...args,
          xr: 1,
          u: {
            u: args.u,
          },
        });
      };

      return true;
    }

    return false;
  })();

  // Redirect
  if (!hooked && redirectUri === null) {
    location.href = `/?redirectUri=${encodeURI(location.href)}`;
    return;
  }

  // Clear body event
  (() => {
    const temp = document.createElement("DIV");

    temp.append(...document.body.childNodes);

    document.body.outerHTML = document.body.outerHTML;
    document.body.innerHTML = "";
    document.body.append(...temp.childNodes);
  })();

  // Reload lib
  __SCRIPTS.syncLoad("forum", "loaderRead", () => {
    if (_LOADERREAD) {
      _LOADERREAD.init();

      // Reload page
      if (redirectUri) {
        ui.htmlLoader.go(33, {
          url: encodeURI(decodeURI(redirectUri)),
        });
      }
    }
  });
})(window);