Greasy Fork is available in English.
Quicly insert text into your post and send it automatically (or nah)
当前为
// ==UserScript==
// @name HF insertText()
// @namespace HF
// @description Quicly insert text into your post and send it automatically (or nah)
// @include http://www.hackforums.net/*
// @require http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js
// @version 1.1
// @grant GM_getValue
// @grant GM_setValue
// @grant GM_deleteValue
// ==/UserScript==
var customText = [];
var sendFor = [];
for (i=1; i<6; i++) {
customText[i] = GM_getValue('customText['+i+']', '');
sendFor[i] = GM_getValue('sendFor['+i+']', 'false');
}
function saveSettings() {
for (nb=1;nb<6;nb++) {
if (document.getElementById('valueTextReplacer' + nb).value.length >= 25) {
GM_setValue('customText[' + nb + ']', document.getElementById('valueTextReplacer' + nb).value)
if (document.getElementById('checkSendAuto' + nb).checked) {
GM_setValue('sendFor[' + nb + ']', true);
} else {
GM_setValue('sendFor[' + nb + ']', false);
}
document.getElementById('submitReplacer').innerHTML = "Changes saved";
} else { alert('You don\'t have more than 25 characters in the field #' + nb + '. Please correct and submit again.'); }
}
}
exportFunction(saveSettings, unsafeWindow, {defineAs: "saveSettings"});
function insertText(nb) {
var prevMessage = document.getElementById("message").value;
document.getElementById('message').value = prevMessage + customText[nb];
if (sendFor[nb]) { document.getElementById('quick_reply_submit').click() }
}
exportFunction(insertText, unsafeWindow, {defineAs: "insertText"});
if (document.URL.indexOf("usercp.php") >= 0) {
var settingsHTML = "<table class='tborder' cellspacing='1' cellpadding='4' border='0'><tbody><tr><td class='thead' colspan='2'><strong> HF Replacer : Settings <button class='button' onclick='saveSettings()'><span id='submitReplacer'>Save</span></button></strong></td></tr><tr><td class='trow1'>Text 1: <textarea style='height:17px;' cols='30' id='valueTextReplacer1'>"+customText[1]+"</textarea> <input id='checkSendAuto1' type='checkbox'><label for='checkSendAuto1'>Send automatically the message ?</label></input> <br/>Text 2: <textarea style='height:17px;' cols='30' id='valueTextReplacer2'>"+customText[2]+"</textarea> <input id='checkSendAuto2' type='checkbox'><label for='checkSendAuto2'>Send automatically the message ?</label></input> <br/>Text 3: <textarea style='height:17px;' cols='30' id='valueTextReplacer3'>"+customText[3]+"</textarea> <input id='checkSendAuto3' type='checkbox'><label for='checkSendAuto3'>Send automatically the message ?</label></input> <br/>Text 4: <textarea style='height:17px;' cols='30' id='valueTextReplacer4'>"+customText[4]+"</textarea> <input id='checkSendAuto4' type='checkbox'><label for='checkSendAuto4'>Send automatically the message ?</label></input> <br/>Text 5: <textarea style='height:17px;' cols='30' id='valueTextReplacer5'>"+customText[5]+"</textarea> <input id='checkSendAuto5' type='checkbox'><label for='checkSendAuto5'>Send automatically the message ?</label></input></td></tr></table><br />";
$('.quick_keys > table:nth-child(1) > tbody:nth-child(1) > tr:nth-child(1) > td:nth-child(2) > br:nth-child(2)').after(settingsHTML);
if (sendFor[1]) { document.getElementById('checkSendAuto1').setAttribute('checked', 'checked'); }
if (sendFor[2]) { document.getElementById('checkSendAuto2').setAttribute('checked', 'checked'); }
if (sendFor[3]) { document.getElementById('checkSendAuto3').setAttribute('checked', 'checked'); }
if (sendFor[4]) { document.getElementById('checkSendAuto4').setAttribute('checked', 'checked'); }
if (sendFor[5]) { document.getElementById('checkSendAuto5').setAttribute('checked', 'checked'); }
}
if (document.URL.indexOf("showthread.php") >= 0) {
var bLocation = document.querySelectorAll('#quickreply_e > tr:nth-child(2) > td:nth-child(1)');
var br = document.createElement('br');
bLocation[0].appendChild(br);
var button = document.createElement('a');
button.appendChild(document.createTextNode(customText[1].substr(0,10)));
button.setAttribute('title', 'Custom Text');
button.setAttribute('onClick', 'insertText(1)');
button.setAttribute('class', 'button');
bLocation[0].appendChild(button);
var button = document.createElement('a');
button.appendChild(document.createTextNode(customText[2].substr(0,10)));
button.setAttribute('title', 'Custom Text');
button.setAttribute('onClick', 'insertText(2)');
button.setAttribute('class', 'button');
bLocation[0].appendChild(button);
var button = document.createElement('a');
button.appendChild(document.createTextNode(customText[3].substr(0,10)));
button.setAttribute('title', 'Custom Text');
button.setAttribute('onClick', 'insertText(3)');
button.setAttribute('class', 'button');
bLocation[0].appendChild(button);
var button = document.createElement('a');
button.appendChild(document.createTextNode(customText[4].substr(0,10)));
button.setAttribute('title', 'Custom Text');
button.setAttribute('onClick', 'insertText(4)');
button.setAttribute('class', 'button');
bLocation[0].appendChild(button);
var button = document.createElement('a');
button.appendChild(document.createTextNode(customText[5].substr(0,10)));
button.setAttribute('title', 'Custom Text');
button.setAttribute('onClick', 'insertText(5)');
button.setAttribute('class', 'button');
bLocation[0].appendChild(button);
}