论坛快捷回帖

使用自定义内容或本扩展预定义的回帖内容,快捷回复支持的论坛的发帖!

目前為 2018-06-12 提交的版本,檢視 最新版本

  1. // ==UserScript==
  2. // @name 论坛快捷回帖
  3. // @namespace http://bmqy.net/
  4. // @version 0.2.0.4
  5. // @description 使用自定义内容或本扩展预定义的回帖内容,快捷回复支持的论坛的发帖!
  6. // @author bmqy
  7. // @match */thread*.*
  8. // @match */forum.php?mod==viewthread
  9. // @match */forum.php?mod=viewthread
  10. // @match */forum/forum.php?mod=viewthread
  11. // @match */forum/thread*.*
  12. // @match */bbs/forum.php?mod=viewthread
  13. // @match */forum.php?mod=post
  14. // @grant GM_getValue
  15. // @grant GM_setValue
  16. // @grant GM_addValueChangeListener
  17. // ==/UserScript==
  18.  
  19. (function() {
  20. 'use strict';
  21. var QuickReply = {
  22. options: {
  23. bEnabled: true,
  24. sTarget: '#fastposteditor',
  25. sTargetMessage: '#fastpostmessage',
  26. sTargetFloat: '#floatlayout_reply',
  27. sTargetFloatMessage: '#postmessage',
  28. sTargetReplyfastBtn: '.replyfast',
  29. sQuickReplyWarp: 'quickReplyWarp',
  30. sQuickReplySelect: 'quickReplySelect',
  31. sQuickReplyCustom: 'quickReplyCustom',
  32. sCustomKey: 'replysCustom',
  33. aReplysDefault: [
  34. '感谢楼主分享,支持一下!',
  35. '支持一下,希望楼主做的更好,加油!',
  36. '做的不错哦,楼主加油,期待更好的作品!',
  37. '标记一下,先看看好不好,谢谢楼主咯!'
  38. ]
  39. },
  40.  
  41. setItem: function(key, value){
  42. GM_setValue(key, value);
  43. },
  44.  
  45. getItem: function(key){
  46. var arr = [];
  47. if(GM_getValue(key) && GM_getValue(key).length > 0){
  48. arr = GM_getValue(key);
  49. }
  50. else{
  51. arr = this.options.aReplysDefault;
  52. }
  53. return arr;
  54. },
  55.  
  56. updateReplysSelect: function (obj, arrReplys){
  57. obj.options.length = 0;
  58. for(var i=0;i<arrReplys.length;i++){
  59. obj.options.add(new Option(arrReplys[i], i));
  60. }
  61. },
  62.  
  63. updateReplysCustom: function(obj, arrReplys){
  64. var _tempAReplys = '';
  65. for(var i=0;i<arrReplys.length; i++){
  66. _tempAReplys += arrReplys[i] +'\n';
  67. }
  68. obj.value = _tempAReplys;
  69. },
  70.  
  71. getQuickReply: function(sTarget, sTargetMessage){
  72. var _this = this;
  73. var oTarget = (typeof sTarget === 'undefined') ? document.querySelector(_this.options.sTarget) : document.querySelector(sTarget);
  74. var oTargetMessage = (typeof sTargetMessage === 'undefined') ? document.querySelector(_this.options.sTargetMessage) : document.querySelector(sTargetMessage);
  75.  
  76. var oQuikReplyWarp = document.createElement('div');
  77. oQuikReplyWarp.id = _this.options.sQuickReplyWarp;
  78.  
  79. var oQuikReplyLabel = document.createElement('label');
  80. oQuikReplyLabel.style = 'color:red;font-weight:bolder';
  81. oQuikReplyLabel.innerHTML = '快捷回帖:';
  82. var oQuikReplySelect = document.createElement('select');
  83. oQuikReplySelect.id = _this.options.sQuickReplySelect;
  84. _this.updateReplysSelect(oQuikReplySelect, _this.getItem(_this.options.sCustomKey));
  85.  
  86. oQuikReplySelect.addEventListener('change', function(e){
  87. oTargetMessage.value = this.options[this.selectedIndex].text;
  88. oTargetMessage.style.background = 'none';
  89. });
  90.  
  91. var oQuickReplyBtnCustom = document.createElement('a');
  92. oQuickReplyBtnCustom.innerHTML = '自定义回帖';
  93. oQuickReplyBtnCustom.href = 'javascript:;';
  94. oQuickReplyBtnCustom.style = "margin-left:10px;color:#999;font-size:12px;";
  95.  
  96. oQuickReplyBtnCustom.addEventListener('click', function(e){
  97. var _posX = e.clientX;
  98. var _posY = e.clientY;
  99. var oQuickReplyCustom = document.querySelector('#'+ _this.options.sQuickReplyCustom);
  100.  
  101. oQuickReplyCustom.style.top = _posY - 280 +'px';
  102. oQuickReplyCustom.style.left = _posX - 150 +'px';
  103. oQuickReplyCustom.style.display = 'block';
  104. });
  105.  
  106. oQuikReplyLabel.appendChild(oQuikReplySelect);
  107. oQuikReplyWarp.appendChild(oQuikReplyLabel);
  108. oQuikReplyWarp.appendChild(oQuickReplyBtnCustom);
  109.  
  110. if(!oTarget.querySelector('#'+ _this.options.sQuickReplyWarp)){
  111. oTarget.insertBefore(oQuikReplyWarp, oTarget.childNodes[0]);
  112. }
  113. },
  114.  
  115. getReplysCustom: function(sTarget, sTargetMessage){
  116. var _this = this;
  117. var oTarget = (typeof sTarget === 'undefined') ? document.querySelector(_this.options.sTarget) : document.querySelector(sTarget);
  118. var oTargetMessage = (typeof sTargetMessage === 'undefined') ? document.querySelector(_this.options.sTargetMessage) : document.querySelector(sTargetMessage);
  119.  
  120. if(document.querySelector('#'+ _this.options.sQuickReplyCustom)){
  121. return false;
  122. }
  123.  
  124. var oCustomPanel = document.createElement('div');
  125. oCustomPanel.id = _this.options.sQuickReplyCustom;
  126. oCustomPanel.style = 'width:280px;height:190px;text-align:center;background-color: #fff;padding:10px;box-shadow:0 0 3px 5px #ddd;position:fixed;left:50%;top:13%;display:none;';
  127.  
  128. var oCustomTips = document.createElement('p');
  129. oCustomTips.style = 'text-align:left;';
  130. oCustomTips.innerHTML = '<font color="red">* 一行一条,请注意回车换行</font>';
  131.  
  132. var oCustomTextarea = document.createElement('textarea');
  133. oCustomTextarea.style = 'width:96%;padding:5px;';
  134. oCustomTextarea.rows = '7';
  135. _this.updateReplysCustom(oCustomTextarea, _this.getItem(_this.options.sCustomKey));
  136.  
  137. var oCustomSaveBtn = document.createElement('button');
  138. oCustomSaveBtn.style = 'width: 100%;';
  139. oCustomSaveBtn.innerHTML = '保存';
  140.  
  141. oCustomSaveBtn.addEventListener('click', function(){
  142. var oQuickReplySelect = document.querySelector('#'+ _this.options.sQuickReplySelect);
  143. var _customReply = oCustomTextarea.value.split('\n');
  144. var _tempArr = [];
  145.  
  146. for(var i=0; i<_customReply.length; i++){
  147. if(_customReply[i] !== ''){
  148. _tempArr.push(_customReply[i]);
  149. }
  150. }
  151. if(_tempArr.length === 0){
  152. _tempArr = _this.options.aReplysDefault;
  153. }
  154. oCustomPanel.style.display = 'none';
  155. _this.setItem(_this.options.sCustomKey, _tempArr);
  156. });
  157.  
  158. oCustomPanel.appendChild(oCustomTextarea);
  159. oCustomPanel.appendChild(oCustomTips);
  160. oCustomPanel.appendChild(oCustomSaveBtn);
  161. document.body.appendChild(oCustomPanel);
  162. },
  163.  
  164. addListenConfig: function(){
  165. var _this = this;
  166. GM_addValueChangeListener(_this.options.sCustomKey, function(name, old_value, new_value, remote){
  167. var aNewReplyCustom = new_value;
  168. var oQuickReplySelect = null;
  169. if(document.querySelector(_this.options.sTarget)){
  170. oQuickReplySelect = document.querySelector(_this.options.sTarget +' #'+ _this.options.sQuickReplySelect);
  171. _this.updateReplysSelect(oQuickReplySelect, aNewReplyCustom);
  172. document.querySelector(_this.options.sTargetMessage).value = aNewReplyCustom[0];
  173. }
  174. if(document.querySelector(_this.options.sTargetFloat)){
  175. oQuickReplySelect = document.querySelector(_this.options.sTargetFloat +' #'+ _this.options.sQuickReplySelect);
  176. _this.updateReplysSelect(oQuickReplySelect, aNewReplyCustom);
  177. document.querySelector(_this.options.sTargetFloatMessage).value = aNewReplyCustom[0];
  178. }
  179. });
  180. },
  181.  
  182. bindReplyfast: function(){
  183. var _this = this;
  184. var oBtnReplyFast = document.querySelector(_this.options.sTargetReplyfastBtn);
  185. oBtnReplyFast.addEventListener('click', function(){
  186. document.addEventListener('DOMNodeInserted', function(e){
  187. if(e.target.id === 'postform'){
  188. var sTargetFloat = _this.options.sTargetFloat;
  189. var sTargetFloatMessage = _this.options.sTargetFloatMessage;
  190. _this.initAfter(sTargetFloat, sTargetFloatMessage);
  191. _this.getQuickReply(sTargetFloat, sTargetFloatMessage);
  192. _this.getReplysCustom(sTargetFloat, sTargetFloatMessage);
  193. }
  194. });
  195. });
  196. },
  197.  
  198.  
  199. initAfter: function(sTarget, sTargetMessage){
  200. var _this = this;
  201. var oTarget = (typeof sTarget === 'undefined') ? document.querySelector(_this.options.sTarget) : document.querySelector(sTarget);
  202. var oTargetMessage = (typeof sTargetMessage === 'undefined') ? document.querySelector(_this.options.sTargetMessage) : document.querySelector(sTargetMessage);
  203.  
  204. oTargetMessage.value = _this.getItem(_this.options.sCustomKey)[0];
  205. oTargetMessage.style.background = 'none';
  206. },
  207.  
  208. init: function(opt){
  209. for(var k in opt){
  210. this.options[k] = opt[k];
  211. }
  212. if(!this.options.bEnabled){
  213. return false;
  214. }
  215.  
  216. if(document.querySelector(this.options.sTarget)){
  217. this.initAfter();
  218. this.getQuickReply();
  219. this.getReplysCustom();
  220. }
  221. this.bindReplyfast();
  222. this.addListenConfig();
  223. }
  224. };
  225.  
  226. QuickReply.init();
  227. })();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址