|
最近发转载指路比较多,为了更方便套个人模板就做了这个脚本惹 安装以后在发新帖页面的左侧空白区域会出来一个模板选择面板 点击即可覆盖当前内容 获取模板数据的例子: 比如我上一篇文学转载的帖子 帖头帖尾是用旅程金币血液等属性图标组成的条条 中间是艺术字的“文章标签”“文章文案”等图片 假如我想之后发文学转载都用这个模板 那就进入它的编辑页面,然后把其他内容删掉(最后记得不要提交编辑) 然后点右上角纯文本,在纯文本模式下,全选帖子内容,复制到脚本里对应位置 之后发帖点一下套模板就能更方便一些了,省了从已发帖复制粘贴的步骤 新帖使用以后是上面这个样子,再点两下纯文本就能让它变成普通模式下的样子,然后就可以正常编辑了 - // ==UserScript==
- // @name 便捷选择发帖模板
- // @namespace [url]http://tampermonkey.net/[/url]
- // @version 1.6
- // @author rober & Assistant
- // @match *://www.gamemale.com/forum.php?mod=post&action=newthread*
- // @run-at document-start
- // @grant none
- // ==/UserScript==
- (function() {
- 'use strict';
- // === 【用户自定义模板区域】 ===
- const TEMPLATES = {
- "33模板": `3333
- 33
- 3`,
- "11模板": `1111111`,
- "22模板": `[b][color=red]★ 2222 ★[/color][/b]2222222`,
- "44模板": `4444444`,
- };
- // === 核心逻辑 ===
- const applyTemplate = (text) => {
- if (!confirm('确定要覆盖当前内容吗?')) return;
- const ta = document.getElementById('e_textarea');
- if (ta) ta.value = text;
- try {
- const ifr = document.getElementById('e_iframe').contentWindow.document;
- ifr.body.innerHTML = text.split('\n').map(l => `<div>${l.trim() ? l : '<br>'}</div>`).join('');
- } catch (e) {}
- };
- const injectStyles = () => {
- const style = document.createElement('style');
- style.textContent = `
- #gm-panel { position: absolute; left: -140px; top: 61px; width: 130px; background: #F9F9F9; border: 1px solid #CCC; border-radius: 4px; z-index: 100; font-family: sans-serif; overflow: hidden; }
- #gm-header { font-size: 12px; font-weight: bold; color: #444; background: #EEE; padding: 6px; border-bottom: 1px solid #CCC; text-align: center; }
- .gm-btn-box { padding: 8px; display: flex; flex-direction: column; gap: 6px; }
- .gm-btn { padding: 6px 4px; background: #FFF; border: 1px solid #DCDCDC; color: #555; border-radius: 2px; cursor: pointer; font-size: 12px; transition: 0.1s; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
- .gm-btn:hover { border-color: #999; background: #F0F0F0; color: #000; }
- `;
- document.head.appendChild(style);
- };
- const observer = new MutationObserver((_, obs) => {
- const postBox = document.getElementById('postbox');
- if (postBox) {
- obs.disconnect();
- postBox.style.position = 'relative';
- injectStyles();
- const panel = document.createElement('div');
- panel.id = 'gm-panel';
- panel.innerHTML = `<div id="gm-header">模板选择</div><div class="gm-btn-box"></div>`;
- const box = panel.querySelector('.gm-btn-box');
- Object.keys(TEMPLATES).forEach(name => {
- const btn = document.createElement('button');
- btn.className = 'gm-btn';
- btn.textContent = name;
- btn.type = 'button';
- btn.onclick = () => applyTemplate(TEMPLATES[name]);
- box.appendChild(btn);
- });
- postBox.appendChild(panel);
- }
- });
- observer.observe(document.documentElement, { childList: true, subtree: true });
- })();
复制代码 
|