Bitcoin Forum
October 03, 2026, 05:51:26 PM *
News: Latest Bitcoin Core release: 31.1 [Torrent]
 
   Home   Help Search Login Register More  
Pages: « 1 [2]  All
  Print  
Author Topic: [Userscript] Automatically Format Pasted URLs as [url=...]Text[/url]  (Read 522 times)
joker_josue
Legendary
*
Offline

Activity: 2534
Merit: 7536


**In BTC since 2013**


View Profile WWW
October 02, 2026, 06:41:31 AM
 #21

This script is very interesting and I believe it could be useful.
Personally, I've never felt the need for it, and I don't like using extra scripts, but I recognize the usefulness of the tool.



Maybe scrap the website title from where you copied the contenttto fill the "change_text"
I have thought of this as well, i even tried it, but there are lots of issues, one is CORS problem, some sites don't work well. Also, it takes time, like several seconds, which is not appropriate how fast copy and paste is and knowing how patience work for some of most, so i abandoned the idea lol

So what if this is an option for a specific button or key combination?
Waiting a few seconds is no longer an issue, because it's responding to a specific user request.

But my idea is a bit more advanced, and good for those who often quote.

My idea would be to copy text from a website, and then, upon clicking a specific button, it would create something like this:
Code:
[quote="link_to_quote"]quoted_content_copied[/quote]

In other words, when someone copies text, they also take with them the link to the page where the text was copied.

Perhaps it's too complex. Especially since it's an idea coming from someone who doesn't even use this type of script.  Lips sealed Roll Eyes

▄███████████████████████▄
█████████████████████████
██████████▀▄▄▄▀██████████
█████████░█████░█████████
████████▀▀░▄▄▄░▀█████████
███████░░░█████░░░███████
██████░░░▐█████▌░░░██████
██████░░░▐█████▌░░░██████
██████░░░▐█████▌░░░██████
███████░░░█████░░░███████
████████▄▄░▀▀▀░▄█████████
█████████████████████████
▀███████████████████████▀
 
 Lock.com 
█▀▀
█
█
█
█
█
█
█
█
█
█
█
█▄▄
▀▀█
█
█
█
█
█
█
█
█
█
█
█
▄▄█
█▀▀
█
█
█
█
█
█
█
█
█
█
█
█▄▄
▀▀█
█
█
█
█
█
█
█
█
█
█
█
▄▄█
 
  Open − code isolated Crypto Wallet     Sign Up    
Royal Cap
Sr. Member
****
Offline

Activity: 602
Merit: 281



View Profile WWW
October 02, 2026, 11:30:22 AM
Merited by joker_josue (2), PX-Z (1)
 #22


My idea would be to copy text from a website, and then, upon clicking a specific button, it would create something like this:
Code:
[quote="link_to_quote"]quoted_content_copied[/quote]
I think you might have wanted such a script. I have presented it below through GIF.



Although TryNinja had made such an already ready script before, which is [UserScript] Copy post quote snip to clipboard (with browser highlight URL). But it only worked inside this forum. But you wanted that if we copy something from an external website, we can also quote it here with just one click.

So I tried to make that. But before that, let me say that all the credits go to PX-Z and TryNinja. I just tried to solve the problem of joker_josue and myself here.

So below I am giving the code.
Code:
// ==UserScript==
// @name         Universal Quick Quote with Text Fragment Formatter
// @version      1.0
// @description  Copy selected text as a BBCode quote from Bitcointalk or any website
// @author       TryNinja + PX-Z + Modified by Royal Cap
// @match        *://*/*
// @icon         https://bitcointalk.org/favicon.ico
// @grant        GM_setClipboard
// @run-at       document-end
// ==/UserScript==

(function () {
    'use strict';

    const btn = document.createElement('button');
    Object.assign(btn.style, {
        position: 'absolute',
        display: 'none',
        zIndex: '2147483647',
        padding: '5px 10px',
        background: '#e7eaef',
        border: '1px solid #000',
        borderRadius: '3px',
        cursor: 'pointer',
        fontSize: '11px',
        fontWeight: 'bold',
        boxShadow: '2px 2px 5px rgba(0,0,0,.2)',
        color: '#000'
    });
    btn.textContent = '❝ Copy Quote';
    document.body.appendChild(btn);

    let selectedText = '', selectedPost = null;
    const isBT = location.hostname.includes('bitcointalk.org');

    const hide = () => btn.style.display = 'none';

    function encode(text) {
        return encodeURIComponent(text).replace(/'/g, '%27');
    }

    function fragment(text) {
        const clean = text.replace(/\s+/g, ' ').trim();
        const words = clean.split(' ');
        if (words.length <= 8) return encode(clean);
        return `${encode(words.slice(0, 4).join(' '))},${encode(words.slice(-4).join(' '))}`;
    }

    function date() {
        const d = new Date();
        const m = ['January','February','March','April','May','June','July','August','September','October','November','December'];
        return `${m[d.getMonth()]} ${d.getDate()}, ${d.getFullYear()}`;
    }

    function findPost(node) {
        if (!isBT || !node) return null;
        if (node.nodeType === Node.TEXT_NODE) node = node.parentElement;
        return node?.closest('div.post') || null;
    }

    function author(post) {
        const content = post?.closest('td.td_headerandpost');
        const a = content?.previousElementSibling?.querySelector('b > a');
        return a?.textContent.trim() || 'Unknown Author';
    }

    function postDate(post) {
        const content = post?.closest('td.td_headerandpost');
        const subject = content?.querySelector('div.subject');
        const small = subject?.parentElement?.querySelector('.smalltext');
        if (!small) return date();

        let d = small.textContent.trim();
        return d.startsWith('Today')
            ? d.replace('Today', date()).replace(' at ', ', ')
            : d;
    }

    function postUrl(post) {
        const content = post?.closest('td.td_headerandpost');
        const link = content?.querySelector('div.subject a') ||
                     content?.querySelector('a[href*="#msg"]');
        const url = link?.href || location.href;
        const parts = url.split('#');
        const base = parts[0].split(';')[0];
        return parts[1] ? `${base}#${parts[1]}` : base;
    }

    function siteName() {
        const meta = document.querySelector('meta[property="og:site_name"]');
        if (meta?.content) return meta.content.trim();

        return location.hostname
            .replace(/^www\./, '')
            .split('.')[0]
            .replace(/[-_]/g, ' ')
            .replace(/\b\w/g, c => c.toUpperCase());
    }

    document.addEventListener('mouseup', e => {
        if (e.target === btn) return;

        setTimeout(() => {
            const selection = window.getSelection();
            if (!selection?.rangeCount) return hide();

            selectedText = selection.toString().trim();
            if (!selectedText) return hide();

            selectedPost = findPost(selection.anchorNode);

            const rect = selection.getRangeAt(0).getBoundingClientRect();
            if (!rect.width && !rect.height) return hide();

            let left = scrollX + rect.left;
            if (left + 120 > scrollX + innerWidth)
                left = scrollX + innerWidth - 130;

            btn.style.left = `${left}px`;
            btn.style.top = `${scrollY + rect.bottom + 5}px`;
            btn.style.display = 'block';
        }, 10);
    });

    document.addEventListener('mousedown', e => {
        if (e.target !== btn) hide();
    });

    btn.addEventListener('click', () => {
        if (!selectedText) return;

        try {
            const f = fragment(selectedText);
            let pageUrl = location.href.replace(/#:~:text=.*$/, '');
            let url = `${pageUrl}#:~:text=${f}`;
            let header;

            if (isBT && selectedPost) {
                const a = author(selectedPost);
                const d = postDate(selectedPost);
                url = `${postUrl(selectedPost)}#:~:text=${f}`;
                header = `[url=${url}]${a} on ${d}[/url]`;
            } else {
                header = `[url=${url}]${siteName()}[/url]`;
            }

            const quote =
                `[quote="${header}"]\n${selectedText}\n[/quote]`;

            GM_setClipboard(quote);

            btn.textContent = 'Copied!';
            btn.style.background = '#dff0d8';
            btn.style.color = '#3c763d';

            setTimeout(() => {
                btn.textContent = '❝ Copy Quote';
                btn.style.background = '#e7eaef';
                btn.style.color = '#000';
                hide();
            }, 1000);

        } catch (err) {
            console.error('[Quick Quote Error]', err);
            btn.textContent = 'Error';
            btn.style.background = '#f2dede';
            btn.style.color = '#a94442';

            setTimeout(() => {
                btn.textContent = '❝ Copy Quote';
                btn.style.background = '#e7eaef';
                btn.style.color = '#000';
                hide();
            }, 1500);
        }
    });
})();

PX-Z (OP)
Legendary
*
Offline

Activity: 2324
Merit: 1406



View Profile WWW
October 02, 2026, 02:01:09 PM
Merited by Crypto Library (1)
 #23


My idea would be to copy text from a website, and then, upon clicking a specific button, it would create something like this:
Code:
[quote="link_to_quote"]quoted_content_copied[/quote]
I think you might have wanted such a script. I have presented it below through GIF.
...
Nice! I hadn't thought of adding this since i couldn't quite figure out how to approach the idea yet. Kudos to you for the contribution, and thanks to @Crypto Library as well for sharing the other version. Open source is truly a great thing!

.◼.◼.Vega.bet.◼.◼.██
██
██
██
██
██
██
██
██
██
██
██
██

...100 FS + 750% BONUS..MAX.WIN.$5,000...

███...FAST PAYOUTS  |  NO KYC  |  10% LOSSBACK...███
██
██
██
██
██
██
██
██
██
██
██
██
██

...Play Now...
joker_josue
Legendary
*
Offline

Activity: 2534
Merit: 7536


**In BTC since 2013**


View Profile WWW
October 02, 2026, 05:41:44 PM
Merited by Crypto Library (1)
 #24


My idea would be to copy text from a website, and then, upon clicking a specific button, it would create something like this:
Code:
[quote="link_to_quote"]quoted_content_copied[/quote]
I think you might have wanted such a script. I have presented it below through GIF.
...
Nice! I hadn't thought of adding this since i couldn't quite figure out how to approach the idea yet. Kudos to you for the contribution, and thanks to @Crypto Library as well for sharing the other version. Open source is truly a great thing!


It's not that it solves any problem for me.Because I don't have a problem with that.

But, I believe it can be useful for many users.

Congratulations on your contributions.

▄███████████████████████▄
█████████████████████████
██████████▀▄▄▄▀██████████
█████████░█████░█████████
████████▀▀░▄▄▄░▀█████████
███████░░░█████░░░███████
██████░░░▐█████▌░░░██████
██████░░░▐█████▌░░░██████
██████░░░▐█████▌░░░██████
███████░░░█████░░░███████
████████▄▄░▀▀▀░▄█████████
█████████████████████████
▀███████████████████████▀
 
 Lock.com 
█▀▀
█
█
█
█
█
█
█
█
█
█
█
█▄▄
▀▀█
█
█
█
█
█
█
█
█
█
█
█
▄▄█
█▀▀
█
█
█
█
█
█
█
█
█
█
█
█▄▄
▀▀█
█
█
█
█
█
█
█
█
█
█
█
▄▄█
 
  Open − code isolated Crypto Wallet     Sign Up    
Pages: « 1 [2]  All
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!