复制代码- // ==UserScript==
- // @name South-Plus Enhancement
- // @namespace http://summer-plus.net/
- // @version 0.1
- // @description South-Plus Enhancement
- // @author nideii
- // @include http*://summer-plus.net/*
- // @include http*://summer-plus.net/*
- // @include http*://summer-plus.net/*
- // @include http*://summer-plus.net/*
- // @include http*://summer-plus.net/*
- // @include http*://*.level-plus.net/*
- // @include http*://*.south-plus.net/*
- // @include http*://*.south-plus.org/*
- // @include http*://*.white-plus.net/*
- // @include http*://*.imoutolove.me/*
- // @require https://cdn.jsdelivr.net/npm/jquery@3/dist/jquery.min.js
- // @require https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.12.0/underscore-min.js
- // @require https://cdn.jsdelivr.net/npm/clipboard@2/dist/clipboard.min.js
- // @run-at document-idle
- // @grant GM_addStyle
- // ==/UserScript==
- (function () {
- 'use strict';
- GM_addStyle(`
- #topbutton {
- display: inline-block;
- border-radius: 3px;
- color: #fff!important;
- line-height: 20px;
- transition: all .5s ease-in-out;
- background: linear-gradient(180deg,#90a4ae,#78909c);
- width: 40px;
- height: 40px;
- position: fixed;
- right: 10px;
- bottom: 40px;
- z-index: 1000001;
- cursor: pointer;
- }
- #topbutton:hover {
- cursor: pointer;
- background: linear-gradient(180deg,#78909c,#546e7a);
- }
- #topbutton.show {
- opacity: 1;
- visibility: visible;
- }
- #topbutton svg {
- position: absolute;
- left: 0;
- top: 0;
- right: 0;
- bottom: 0;
- width: 10px;
- height: 10px;
- margin: auto;
- fill: #fff
- }
- `);
- $('body').append(`<div id="topbutton">
- <svg data-markup-inline="" alt="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"
- version="1.1" x="0px" y="0px" width="349.629px" height="349.629px" viewBox="0 0 349.629 349.629"
- xml:space="preserve">
- <polygon
- points="174.827,73.433 0,253.42 23.434,276.19 174.827,120.318 326.216,276.196 349.629,253.42 ">
- </polygon>
- </svg>
- </div>`);
- let topbtn = $('#topbutton');
- $(window).scroll(() => $(window).scrollTop() > 300 ? topbtn.show() : topbtn.hide());
- topbtn.click(() => $('html, body').animate({ scrollTop: 0 }, '300'));
- let buyers_list = $('select[name="buyers"]');
- let quote_info = $('h6.quote.jumbotron > span.s3');
- if (buyers_list.length == 0) {
- return;
- }
- if (buyers_list.length != quote_info.length) {
- console.error('buyers_list.length != quote_info.length');
- return;
- }
- const thread_title = '\n' + $($('h1#subject_tpc')[0]).text() + '\n';
- let rapid = 1;
- for (let block of $('blockquote.blockquote.jumbotron')) {
- let links = [];
- let rows = 0;
- const text = block.innerText;
- const lines = text.split('\n');
- for (const [i, line] of lines.entries()) {
- let m = line.match(/([A-Fa-f0-9]{32}#[A-Fa-f0-9]{32}#[0-9]+#)(.*)/);
- if (m == null || m.length != 3) {
- continue;
- }
- links.push([m[1], m[2]]);
- }
- if (links.length == 0) {
- continue;
- }
- let link_text = '';
- for (const [i, [finfo, fname]] of links.entries()) {
- link_text += `${finfo}\n{prefix}\n${fname}\n`;
- rows += 3;
- if (i != links.length - 1) {
- link_text += '---\n';
- rows += 1;
- }
- }
- rows = rows > 10 ? 12 : rows + 2;
- $(`<button type="button" class="bdrapid-btn" data-rapid="${rapid}"
- style="border: 1px solid #dddddd; margin-bottom: 2px;">复制秒链</button>`).insertBefore(block);
- $(`<button type="button" class="bdrapid-clear-btn" data-rapid="${rapid}"
- style="border: 1px solid #dddddd; margin: 0 0 2px 2px;">清空前缀</button><br>`).insertBefore(block);
- $(`<textarea id="bdrapid-prefix-${rapid}" style="width:85%" rows="3"></textarea>`).insertBefore(block).val(thread_title);
- $(`<textarea id="bdrapid-${rapid}" style="width:85%" rows="${rows}">${link_text}</textarea>`).insertBefore(block);
- rapid += 1;
- }
- const num_quote = buyers_list.length;
- const li_style_1 = ' style="cursor: pointer;"';
- const li_style_2 = ' style="cursor: pointer;border-left:1px solid #eeeeee;"';
- let jump_list = '';
- for (let [i, [attach, info]] of _.zip(buyers_list, quote_info).entries()) {
- let purchased = false;
- for (const cls of info.classList) {
- if (cls == 'f12' || cls == 'fn') {
- purchased = true;
- break;
- }
- }
- let sp = $(info).text().match(/此帖售价 ([0-9]+) SP币,已有 [0-9]+ 人购买/)[1];
- sp = ` - ${sp} SP`;
- let reply = attach.closest('div.t5.t2');
- let floor_id = $('div.tiptop > span.fl > a.s3', reply)[0].text.trim();
- // let reply_title = $('div.h1.fl > h1.fl', reply).text();
- // $(`<blockquote class="blockquote jumbotron replytitle">
- // ${reply_title}
- // </blockquote>`)
- // .insertAfter($(info).parent()[0]);
- jump_list += `
- <li${i == 0 ? li_style_1 : li_style_2}>
- <a class="fn jump_quote" quote-id="${i}">
- <input type="checkbox" ${purchased ? 'checked' : ''} disabled ${li_style_1}>
- <label ${li_style_1}>
- ${floor_id}${num_quote > 3 ? '' : sp}
- </label>
- </a>
- </li>`;
- }
- $(`<span class="fl pages"><ul>${jump_list}</ul></span>`).insertBefore('div.t3 > div.c');
- $('a.jump_quote[quote-id]').click(function () {
- let id = parseInt($(this).attr('quote-id'));
- if (id != id || id < 0 || id > buyers_list.length) {
- return;
- }
- buyers_list[id].scrollIntoView(
- { behavior: "auto", block: "center", inline: "nearest" }
- );
- });
- $('button.bdrapid-clear-btn').click(function () {
- const rapid = $(this).attr('data-rapid');
- $(`textarea#bdrapid-prefix-${rapid}`).val('');
- });
- function safe_path(str) {
- var dict = {
- '<': '<',
- '>': '>',
- ':': ':',
- '"': '”',
- ':': ':',
- '/': '/',
- '\\': '\',
- '|': '|',
- '?': '?',
- '*': '*',
- };
-
- for (let k in dict) {
- str = str.replace(k, dict[k]);
- }
- return str;
- }
- new ClipboardJS('.bdrapid-btn', {
- text: function (trigger) {
- const rapid = $(trigger).attr('data-rapid');
- const prefix_val = $(`textarea#bdrapid-prefix-${rapid}`).val();
- let prefix = '';
- for (const [i, line] of prefix_val.split('\n').entries()) {
- if (line.length > 0) {
- prefix += safe_path(line) + '/';
- }
- }
- prefix = prefix.substr(0, prefix.length - 1);
- const link_text = $(`textarea#bdrapid-${rapid}`).val();
- let rapid_links = '';
- for (let line of link_text.split('\n')) {
- if (line == '---') {
- rapid_links += '\n';
- continue;
- }
- if (line == '{prefix}') {
- line = prefix;
- if (line.length > 0) {
- line += '/';
- }
- }
- rapid_links += line;
- }
- console.log(rapid_links);
- return rapid_links;
- }
- });
- })();
|