【脚本】发帖模板便捷选择
本帖最后由 reober3 于 2026-2-26 02:20 编辑https://img.gamemale.com/album/202601/31/182508crl9b1d81vhq8hbv.pnghttps://img.gamemale.com/album/202601/31/182507a3qmmq33z5qz0w10.png最近发转载指路比较多,为了更方便套个人模板就做了这个脚本惹安装以后在发新帖页面的左侧空白区域会出来一个模板选择面板点击即可覆盖当前内容
static/image/hrline/5.gifstatic/image/hrline/5.gif获取模板数据的例子:比如我上一篇文学转载的帖子帖头帖尾是用旅程金币血液等属性图标组成的条条中间是艺术字的“文章标签”“文章文案”等图片假如我想之后发文学转载都用这个模板那就进入它的编辑页面,然后把其他内容删掉(最后记得不要提交编辑)然后点右上角纯文本,在纯文本模式下,全选帖子内容,复制到脚本里对应位置之后发帖点一下套模板就能更方便一些了,省了从已发帖复制粘贴的步骤新帖使用以后是上面这个样子,再点两下纯文本就能让它变成普通模式下的样子,然后就可以正常编辑了@Name @Name@Match@Name@Match // ==UserScript==
// @Name 便捷选择发帖模板
// @namespace http://tampermonkey.net/
// @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模板": `★ 2222 ★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);
box.appendChild(btn);
});
postBox.appendChild(panel);
}
});
observer.observe(document.documentElement, { childList: true, subtree: true });
})();
喜欢的话求求https://img.gamemale.com/album/202601/31/200709y9td6tdetbe58bp8.png惹{:6_195:}{:6_195:}https://img.gamemale.com/album/202601/28/182527wwpaezsweooss551.pnghttps://img.gamemale.com/album/202601/28/191807a1wn89n5xg8o3o3a.png
好东西厚,也是少了找自己帖子复制粘贴的过程{:6_163:} 本人一般都是复制以前的帖子的格式,这样的脚本似乎要更方便一点 很实用的模板,自己发帖老是会注意排版问题 对于喜欢发帖的人还有萌新比较友好,模板简洁明了重点突出,下次试一下 0-0 好家伙 甚至大佬贴心的准备了发帖模板 咸鱼更加懒惰了jpg 对于经常发不同板块的坛友感觉大有裨益呢 一键就能弄出自己想用的模板感觉也太方便了惹:$ 每次排版确实很多问题~感觉对于经常发帖的大佬们特别实用啊~感谢楼主分享很不错哇{:4_91:} 感觉发同一个板块的内容会很有用,直接套用 发帖实用小工具,感谢楼主。:lol 很方便的模板,不过个人如果要发帖会用之前的帖子格式 挺实用的脚本,增加发帖子的便利性了。 很棒的脚本!:$我是真的编写帖子苦手 来参考看看~ 有时候想分享点东西,却老是要东拼西贴有够累的
就算复制自己的格式,不同东西也是有不同的排版,所以这个说不定大派用场,感谢楼主~ 吼~对经常发帖的还挺实用欸~对些强迫症更是友好~ 感谢分享,好严谨的模板hhh让我梦回写硕士论文的时候了{:6_174:} 好不错的东西,像动漫分享之类固定版式的发帖用D指导改改就能用了,超级省时省力{:6_167:} 好东西,真的太棒惹,以前都是自己手动复制的 又一个优化网页设计的脚本,好耶