AGREE 论坛替换 flash 验证码

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

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 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);
}