What's new

Pinay Boso sa Greenhills

Status
Not open for further replies.
// ==UserScript== // Name NSFWPH Quick Reply Tabs // @namespace nsfwph-helper // @version 8.0 // @description Opens threads in new tabs, auto-fills and auto-submits reply with retry until success, closes after posting // @match https://nsfwph.org/* // @grant none // ==/UserScript== (function () { 'use strict'; // -------------------------------- // 1. NEW POSTS PAGE // Open thread links in another tab // -------------------------------- if (location.pathname.includes("/whats-new/")) { document.addEventListener("click", function (event) { const link = event.target.closest( ".structItem-title a" ); if (!link) return; if ( event.ctrlKey || event.shiftKey || event.altKey || event.metaKey ) return; event.preventDefault(); window.open(link.href, "_blank"); }); console.log("Quick Reply: New Posts mode"); return; } // -------------------------------- // 2. THREAD PAGE - AUTO FILL & SUBMIT WITH RETRY // -------------------------------- let retryCount = 0; const MAX_RETRIES = 3; let isProcessing = false; // prevent multiple concurrent attempts function getEditor() { return document.querySelector( ".fr-element[contenteditable='true']" ) || document.querySelector( "[contenteditable='true']" ); } function getPostButton() { const btns = document.querySelectorAll( "button[type='submit'], input[type='submit']" ); for (let btn of btns) { const name = ( btn.innerText || btn.value || "" ).trim().toLowerCase(); if (name === "post" || name === "post reply") { return btn; } } return null; } async function attemptPasteAndSubmit() { if (isProcessing) return; isProcessing = true; try { // Read clipboard const text = await navigator.clipboard.readText(); if (!text || !text.trim()) { console.log("Quick Reply: clipboard empty, aborting."); isProcessing = false; return; } // Find editor const editor = getEditor(); if (!editor) { console.log("Quick Reply: editor not found."); isProcessing = false; return; } // If editor already has content, do not overwrite (manual typing) if (editor.innerText.trim()) { console.log("Quick Reply: editor not empty, skipping paste."); isProcessing = false; return; } // Paste editor.focus(); editor.textContent = text; editor.dispatchEvent( new InputEvent("input", { bubbles: true, inputType: "insertText", data: text }) ); editor.scrollIntoView({ behavior: "smooth", block: "center" }); console.log("Quick Reply: clipboard inserted."); // Wait a moment for XenForo to register await new Promise(resolve => setTimeout(resolve, 600)); // Find and click Post button const submitBtn = getPostButton(); if (!submitBtn) { console.log("Quick Reply: Post button not found."); isProcessing = false; return; } console.log("Quick Reply: clicking Post (attempt " + (retryCount + 1) + ")"); submitBtn.click(); // Now wait to see if post succeeded // We'll check after 3 seconds if editor becomes empty let success = false; let checks = 0; const maxChecks = 10; // 10 * 500ms = 5 seconds await new Promise((resolve) => { const interval = setInterval(() => { checks++; const currentEditor = getEditor(); // If editor is empty, post likely succeeded if (currentEditor && !currentEditor.innerText.trim()) { success = true; clearInterval(interval); resolve(); } else if (checks >= maxChecks) { // Timeout - assume failure clearInterval(interval); resolve(); } }, 500); }); if (success) { console.log("Quick Reply: post successful."); // Close tab if it was opened from another tab setTimeout(() => { if (window.opener) { window.close(); } }, 1000); isProcessing = false; return; } else { // Post failed or not detected console.log("Quick Reply: post not confirmed, retrying..."); retryCount++; if (retryCount >= MAX_RETRIES) { console.log("Quick Reply: max retries reached, giving up."); isProcessing = false; return; } // Wait a bit before retry await new Promise(resolve => setTimeout(resolve, 2000)); // Clear editor if it still has content (to avoid "already has content" check) const ed = getEditor(); if (ed && ed.innerText.trim()) { // Clear it so we can paste again ed.textContent = ''; ed.dispatchEvent(new InputEvent("input", { bubbles: true, inputType: "insertText", data: '' })); } // Retry isProcessing = false; attemptPasteAndSubmit(); // recursive retry } } catch (error) { console.log("Quick Reply: error: " + error); isProcessing = false; } } // -------------------------------- // 3. DETECT MANUAL POST CLICK (for closing tab if manual) // (We keep this for manual clicks, but auto will also close on success) // -------------------------------- document.addEventListener("click", function (event) { const button = event.target.closest( "button[type='submit'], input[type='submit']" ); if (!button) return; const name = ( button.innerText || button.value || "" ).trim().toLowerCase(); if (name !== "post" && name !== "post reply") return; console.log("Quick Reply: manual Post clicked."); // Wait for post success and close if applicable let checks = 0; const watcher = setInterval(() => { checks++; const editor = getEditor(); if (editor && !editor.innerText.trim()) { clearInterval(watcher); console.log("Quick Reply: manual post appears successful."); setTimeout(() => { if (window.opener) { window.close(); } }, 1000); } if (checks >= 30) { clearInterval(watcher); } }, 500); }); // -------------------------------- // 4. START AUTO PROCESS AFTER THREAD LOADS // -------------------------------- setTimeout(attemptPasteAndSubmit, 1500); // -------------------------------- // 5. BIG POST BUTTON STYLE // -------------------------------- const style = document.createElement("style"); style.textContent = .formSubmitRow-controls { text-align: right !important; } button[type="submit"] { min-width: 280px !important; min-height: 80px !important; font-size: 28px !important; font-weight: bold !important; padding: 18px 45px !important; cursor: pointer !important; float: right !important; margin-left: auto !important; margin-right: 10px !important; } ; document.head.appendChild(style); })();
 
Status
Not open for further replies.

About this Thread

  • 16
    Replies
  • 2K
    Views
  • 15
    Participant count
Last reply from:
sxlg02

Trending Topics

Online now

Members online
2,697
Guests online
1,787
Total visitors
4,484

Forum statistics

Threads
562,244
Posts
10,526,058
Members
466,108
Latest member
hehw
Back
Top