编程猫账号保护

保护你的编程猫账号。

질문, 리뷰하거나, 이 스크립트를 신고하세요.
// ==UserScript==
// @name         编程猫账号保护
// @namespace    https://s-lightning.github.io/
// @version      0.0.5
// @description  保护你的编程猫账号。
// @author       SLIGHTNING
// @match        http://*.codemao.cn/*
// @match        https://*.codemao.cn/*
// @icon         https://static.codemao.cn/coco/player/unstable/B1F3qc2Hj.image/svg+xml?hash=FlHXde3J3HLj1PtOWGgeN9fhcba3
// @grant        none
// @license      AGPL-3.0
// @run-at       document-start
// ==/UserScript==

/******/ (function() { // webpackBootstrap
/******/ 	"use strict";
/******/ 	var __webpack_modules__ = ([
/* 0 */,
/* 1 */
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

__webpack_require__.r(__webpack_exports__);
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */   start: function() { return /* binding */ start; }
/* harmony export */ });
/* harmony import */ var _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(2);

function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0,_babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0__["default"])(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
function start() {
  window.SLIGHTNING_ACCOUNT_PROTECT = true;
  setInterval(function () {
    document.cookie = "access-token=0;path=/;domain=.codemao.cn;max-age=" + 30 * 24 * 60 * 60;
  }, 100);
  var interceptResponse = {
    code: 403,
    msg: "该操作被编程猫账号保护脚本拦截",
    error_code: 403,
    error_message: "该操作被编程猫账号保护脚本拦截"
  };
  function onIntercept(url, go, reject, modify) {
    if (/https?:\/\/api\.codemao\.cn\/tiger\/v3\/web\/accounts\/username.*/.test(url)) {
      reject();
    } else if (/https?:\/\/api\.codemao\.cn\/tiger\/v3\/web\/accounts\/tokens\/convert/.test(url)) {
      reject();
    } else if (/https?:\/\/api\.codemao\.cn\/tiger\/v3\/web\/accounts\/privacy/.test(url)) {
      reject();
    } else if (/https?:\/\/api\.codemao\.cn\/web\/users\/details/.test(url)) {
      modify(function (response) {
        if (response.status == 200) {
          var data = JSON.parse(response.text);
          Object.assign(data, {
            birthday: 0,
            phone_number: "***********",
            qq: "****",
            real_name: "已拦截",
            username: "已拦截"
          });
          data = JSON.stringify(data);
          return {
            text: data
          };
        } else {
          return {};
        }
      });
    } else if (/https?:\/\/api\.codemao\.cn\/api\/user\/info/.test(url)) {
      modify(function (response) {
        var data = JSON.parse(response.text);
        if (data.code == 200) {
          Object.assign(data.data, {
            age: 0,
            username: "已拦截",
            telephone: "***********",
            qq: "****",
            email: "****",
            real_name: "已拦截"
          });
          return {
            text: JSON.stringify(response)
          };
        } else {
          return {};
        }
      });
    } else {
      go();
    }
  }
  ;
  (function () {
    var originalFetch = fetch;

    // @ts-ignore
    fetch = function fetch(url, options) {
      var _this = this;
      if (url instanceof Request) {
        url = url.url;
      } else if (url instanceof URL) {
        url = url.href;
      }
      return new Promise(function (resolve, reject) {
        onIntercept(url, function () {
          originalFetch.call(_this, url, options).then(resolve).catch(reject);
        }, function () {
          return new Response(JSON.stringify(interceptResponse), {
            status: 403,
            statusText: "403 Forbidden"
          });
        }, function (callback) {
          var result = originalFetch.call(_this, url, options);
          result.then(function (response) {
            response.text().then(function (originalText) {
              var _callback = callback({
                  status: response.status,
                  text: originalText
                }),
                status = _callback.status,
                text = _callback.text;
              var statusText = response.statusText;
              if (status == null) {
                status = response.status;
              } else {
                statusText = String(status);
              }
              if (text == null) {
                text = originalText;
              }
              resolve(new Response(text, _objectSpread(_objectSpread({}, response), {}, {
                status: status,
                statusText: statusText
              })));
            }).catch(reject);
          }).catch(reject);
        });
      });
    };
  })();
  (function () {
    var originalXMLHttpRequest = XMLHttpRequest;

    // @ts-ignore
    XMLHttpRequest = function XMLHttpRequest() {
      var _this2 = this;
      var XHR = new originalXMLHttpRequest();
      var _loop = function _loop(key) {
        if (typeof XHR[key] == "function") {
          _this2[key] = XHR[key].bind(XHR);
        } else {
          Object.defineProperty(_this2, key, {
            get: function get() {
              return XHR[key];
            },
            set: function set(value) {
              // @ts-ignore
              XHR[key] = value;
            },
            configurable: true,
            enumerable: true
          });
        }
      };
      for (var key in XHR) {
        _loop(key);
      }
      Object.defineProperty(this, "open", {
        value: function value(method, url, async, username, password) {
          if (url instanceof URL) {
            url = url.href;
          }
          this.__url = url;
          this.__openArguments = arguments;
          XHR.open.call(XHR, method, url, async, username, password);
        }
      });
      Object.defineProperty(this, "send", {
        value: function value(body) {
          var _this3 = this;
          onIntercept(this.__url, function () {
            XHR.send.call(XHR, body);
          }, function () {
            reject(_this3);
          }, function (callback) {
            modifyResponse(_this3, function (XHR) {
              var _callback2 = callback({
                  status: XHR.status,
                  text: XHR.responseText
                }),
                status = _callback2.status,
                text = _callback2.text;
              var result = {};
              if (status != null) {
                result.states = status;
                result.statesText = String(status);
              }
              if (text != null) {
                result.response = text;
                result.responseText = text;
              }
              return result;
            });
          });
        }
      });
    };
    XMLHttpRequest.prototype = originalXMLHttpRequest.prototype;
    XMLHttpRequest.prototype.constructor = XMLHttpRequest;
    function forgeResponse(XHR, response) {
      for (var key in response) {
        Object.defineProperty(XHR, key, {
          value: response[key]
        });
      }
      function dispatchEvent(eventType) {
        XHR.dispatchEvent(new Event(eventType));
      }
      dispatchEvent("loadstart");
      Object.defineProperty(XHR, "readyState", {
        value: XHR.DONE
      });
      dispatchEvent("readystatechange");
      if (XHR.status == 200) {
        dispatchEvent("load");
      } else {
        dispatchEvent("error");
      }
      dispatchEvent("loadend");
    }
    function modifyResponse(XHR, callback) {
      var originalXHR = new originalXMLHttpRequest();
      originalXHR.withCredentials = XHR.withCredentials;
      // @ts-ignore
      originalXHR.open.apply(originalXHR, XHR.__openArguments);
      originalXHR.onreadystatechange = function () {
        if (originalXHR.readyState == 4) {
          for (var _i = 0, _arr = ["status", "statusText", "responseType", "response", "responseText"]; _i < _arr.length; _i++) {
            var key = _arr[_i];
            Object.defineProperty(XHR, key, {
              value: originalXHR[key]
            });
          }
          forgeResponse(XHR, callback(XHR));
        }
      };
      originalXHR.send();
    }
    function reject(XHR) {
      forgeResponse(XHR, {
        status: 403,
        statusText: "403 Forbidden",
        responseType: "json",
        response: JSON.stringify(interceptResponse),
        responseText: JSON.stringify(interceptResponse)
      });
    }
  })();
}

/***/ }),
/* 2 */
/***/ (function(__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) {

__webpack_require__.r(__webpack_exports__);
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */   "default": function() { return /* binding */ _defineProperty; }
/* harmony export */ });
/* harmony import */ var _toPropertyKey_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(3);

function _defineProperty(e, r, t) {
  return (r = (0,_toPropertyKey_js__WEBPACK_IMPORTED_MODULE_0__["default"])(r)) in e ? Object.defineProperty(e, r, {
    value: t,
    enumerable: !0,
    configurable: !0,
    writable: !0
  }) : e[r] = t, e;
}


/***/ }),
/* 3 */
/***/ (function(__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) {

__webpack_require__.r(__webpack_exports__);
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */   "default": function() { return /* binding */ toPropertyKey; }
/* harmony export */ });
/* harmony import */ var _typeof_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(4);
/* harmony import */ var _toPrimitive_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(5);


function toPropertyKey(t) {
  var i = (0,_toPrimitive_js__WEBPACK_IMPORTED_MODULE_1__["default"])(t, "string");
  return "symbol" == (0,_typeof_js__WEBPACK_IMPORTED_MODULE_0__["default"])(i) ? i : i + "";
}


/***/ }),
/* 4 */
/***/ (function(__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) {

__webpack_require__.r(__webpack_exports__);
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */   "default": function() { return /* binding */ _typeof; }
/* harmony export */ });
function _typeof(o) {
  "@babel/helpers - typeof";

  return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) {
    return typeof o;
  } : function (o) {
    return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
  }, _typeof(o);
}


/***/ }),
/* 5 */
/***/ (function(__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) {

__webpack_require__.r(__webpack_exports__);
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */   "default": function() { return /* binding */ toPrimitive; }
/* harmony export */ });
/* harmony import */ var _typeof_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(4);

function toPrimitive(t, r) {
  if ("object" != (0,_typeof_js__WEBPACK_IMPORTED_MODULE_0__["default"])(t) || !t) return t;
  var e = t[Symbol.toPrimitive];
  if (void 0 !== e) {
    var i = e.call(t, r || "default");
    if ("object" != (0,_typeof_js__WEBPACK_IMPORTED_MODULE_0__["default"])(i)) return i;
    throw new TypeError("@@toPrimitive must return a primitive value.");
  }
  return ("string" === r ? String : Number)(t);
}


/***/ })
/******/ 	]);
/************************************************************************/
/******/ 	// The module cache
/******/ 	var __webpack_module_cache__ = {};
/******/ 	
/******/ 	// The require function
/******/ 	function __webpack_require__(moduleId) {
/******/ 		// Check if module is in cache
/******/ 		var cachedModule = __webpack_module_cache__[moduleId];
/******/ 		if (cachedModule !== undefined) {
/******/ 			return cachedModule.exports;
/******/ 		}
/******/ 		// Create a new module (and put it into the cache)
/******/ 		var module = __webpack_module_cache__[moduleId] = {
/******/ 			// no module.id needed
/******/ 			// no module.loaded needed
/******/ 			exports: {}
/******/ 		};
/******/ 	
/******/ 		// Execute the module function
/******/ 		__webpack_modules__[moduleId](module, module.exports, __webpack_require__);
/******/ 	
/******/ 		// Return the exports of the module
/******/ 		return module.exports;
/******/ 	}
/******/ 	
/************************************************************************/
/******/ 	/* webpack/runtime/define property getters */
/******/ 	!function() {
/******/ 		// define getter functions for harmony exports
/******/ 		__webpack_require__.d = function(exports, definition) {
/******/ 			for(var key in definition) {
/******/ 				if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
/******/ 					Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
/******/ 				}
/******/ 			}
/******/ 		};
/******/ 	}();
/******/ 	
/******/ 	/* webpack/runtime/hasOwnProperty shorthand */
/******/ 	!function() {
/******/ 		__webpack_require__.o = function(obj, prop) { return Object.prototype.hasOwnProperty.call(obj, prop); }
/******/ 	}();
/******/ 	
/******/ 	/* webpack/runtime/make namespace object */
/******/ 	!function() {
/******/ 		// define __esModule on exports
/******/ 		__webpack_require__.r = function(exports) {
/******/ 			if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
/******/ 				Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
/******/ 			}
/******/ 			Object.defineProperty(exports, '__esModule', { value: true });
/******/ 		};
/******/ 	}();
/******/ 	
/************************************************************************/
var __webpack_exports__ = {};
__webpack_require__.r(__webpack_exports__);
/* harmony import */ var _codemao_account_protect__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(1);

(0,_codemao_account_protect__WEBPACK_IMPORTED_MODULE_0__.start)();
/******/ })()
;