AGREE 论坛替换 flash 验证码

替换掉 AGREE 论坛上的旧 flash 验证码模块

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         AGREE 论坛替换 flash 验证码
// @namespace    Aloxaf
// @version      0.1.0
// @description  替换掉 AGREE 论坛上的旧 flash 验证码模块
// @author       Aloxaf
// @match        http://www.galgamezs.com/bbs/*
// @grant        unsafeWindow
// ==/UserScript==

// jshint esversion: 6

function load_captcha() {
  let flash = document.querySelector('embed');
  let img = document.querySelector('#captcha');
  if (img === null) {
    let parent = document.querySelector('#seccodeswf_3');
    img = document.createElement('img');
    img.id = 'captcha';
    flash.style = 'display: none';
    parent.insertBefore(img, flash);
  }

  let update = flash.attributes.flashvars.textContent.match(/\d+$/)[0];

  fetch(`http://www.galgamezs.com/bbs/seccode.php?update=${update}`, {
    method: 'POST',
    headers: {'Content-Type': 'application/x-www-form-urlencoded'},
    body: 'fromFlash=1',
    credentials: 'same-origin',
  }).then(res => {
    return res.blob();
  }).then(b => {
    let img = document.querySelector('#captcha');
    img.src = window.URL.createObjectURL(b);
  });
}

unsafeWindow.opensecwin3_bak = unsafeWindow.opensecwin3;
unsafeWindow.opensecwin3 = (id, type) => {
  unsafeWindow.opensecwin3_bak(id, type);
  let flash_loaded = setInterval(() => {
    if (document.querySelector('embed') !== null) {
      load_captcha();
      clearInterval(flash_loaded);
    }
  }, 50);
}