增强黎明版

增强黎明版的一些交互

目前為 2021-09-15 提交的版本,檢視 最新版本

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

You will need to install an extension such as Tampermonkey to install this script.

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name        增强黎明版
// @description 增强黎明版的一些交互
// @namespace   no1xsyzy
// @match       http://adnmb.com/*
// @match       https://adnmb.com/*
// @match       http://adnmb1.com/*
// @match       https://adnmb1.com/*
// @match       http://adnmb2.com/*
// @match       https://adnmb2.com/*
// @match       http://adnmb3.com/*
// @match       https://adnmb3.com/*
// @require     https://code.jquery.com/jquery-2.2.4.min.js
// @license     Apache License, Version 2.0 (Apache-2.0); https://opensource.org/licenses/Apache-2.0
// @version     0.4.2
// @author      no1xsyzy
// @grant       GM_setValue
// @grant       GM_getValue
// @grant       GM_deleteValue
// ==/UserScript==
(function ($) {
  'use strict';

  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

  var $__default = /*#__PURE__*/_interopDefaultLegacy($);

  var 正文框 = document.querySelector('textarea.h-post-form-textarea');

  const search = window.location.search;
  const params = {};
  search.replace(/^\?/, '').split('&').forEach(kev => {
    const [k, v] = kev.split('=', 2);
    params[k] = v;
  });

  function 清空编辑 () {
    if (document.getElementsByClassName('success')[0].textContent.includes('回复成功')) {
      const 主串路径 = /https?:\/\/[^/]+(\/t\/\d+)/.exec(document.getElementById('href').href)[1];
      GM_deleteValue(主串路径);
    }
  }

  function 载入编辑 () {
    正文框.value = GM_getValue(window.location.pathname, params.r ? `>>No.${params.r}\n` : '');
  }

  function 注册自动保存编辑 () {
    正文框.addEventListener('change', 保存编辑);
  }

  function 保存编辑 () {
    GM_setValue(window.location.pathname, 正文框.value);
  }

  function 注册追记引用串号 () {
    $__default['default']('body').on('click', 'a.h-threads-info-id', e => {
      if (正文框.value.length > 0 && !正文框.value.endsWith('\n')) {
        正文框.value += '\n';
      }
      正文框.value += `>>${e.target.textContent}\n`;
      保存编辑();
      e.preventDefault();
    });
  }

  function 注册粘贴图片 () {
    window.addEventListener('paste', e => {
      const files = (e.clipboardData || e.originalEvent.clipboardData).files;
      if (files.length) { document.querySelector('input[type="file"][name="image"]').files = files; }
    });
  }

  function 自动标题 () {
    const page = params.page || 1;
    const title = document.querySelector('.h-threads-list .h-threads-item-main .h-threads-info .h-threads-info-title').textContent.trim();
    if (title !== '无标题') {
      document.querySelector('title').textContent = `${title} - page. ${page} - A岛匿名版`;
      return
    }
    const lines = document.querySelector('.h-threads-list .h-threads-item-main .h-threads-content').textContent.split('\n');
    for (let line of lines) {
      if ((line = line.trim()) !== '') {
        document.querySelector('title').textContent = `${line} - page. ${page} - A岛匿名版`;
        return
      }
    }
  }

  function 串 () {
    载入编辑();
    注册追记引用串号();
    注册自动保存编辑();
    注册粘贴图片();
    自动标题();
  }

  function 版块 () {
    注册粘贴图片();
  }

  function 回复成功 () {
    清空编辑();
    注册粘贴图片();
  }

  function 未知 () {
    注册粘贴图片();
  }

  const path = window.location.pathname;
  const pathsegs = path.split('/').splice(1);
  switch (pathsegs[0]) {
    case 't':
      串();
      break
    case 'f':
      版块();
      break
    case 'Forum':
      if (pathsegs[1] === 'po' && pathsegs[2] === 'id') { 版块(); } else { 未知(); }
      break
    case 'Home':
      if (path === '/Home/Forum/doReplyThread.html') { 回复成功(); } else { 未知(); }
      break
    default:
      未知();
  }

}($));