SHOW:
|
|
- or go back to the newest paste.
| 1 | javascript:(function() {
| |
| 2 | - | console.log('Nc6v3.4-2');
|
| 2 | + | console.log('Nc6v3.4-3-fixed-author-only');
|
| 3 | - | |
| 3 | + | |
| 4 | var tweetTexts = []; | |
| 5 | var userTweets = []; | |
| 6 | var imgCounter = 0; | |
| 7 | var globalTweetCount = 0; | |
| 8 | var totalTweetCount = 0; | |
| 9 | var outputChains = []; | |
| 10 | ||
| 11 | - | |
| 11 | + | |
| 12 | var originalAuthor = null; | |
| 13 | var firstTweet = tweets[0]; | |
| 14 | if (firstTweet) {
| |
| 15 | var firstAuthor = firstTweet.querySelector('.username');
| |
| 16 | if (firstAuthor) {
| |
| 17 | originalAuthor = firstAuthor.textContent.slice(1); | |
| 18 | console.log('Original author identified:', originalAuthor);
| |
| 19 | - | |
| 19 | + | |
| 20 | - | |
| 20 | + | |
| 21 | ||
| 22 | ||
| 23 | var originalAuthorTweetUrls = []; | |
| 24 | tweets.forEach(function(tweet) {
| |
| 25 | - | |
| 25 | + | |
| 26 | if (tweetAuthor && tweetAuthor.textContent.slice(1) === originalAuthor) {
| |
| 27 | var tweetLink = tweet.querySelector('.tweet-link a');
| |
| 28 | if (tweetLink) {
| |
| 29 | var tweetUrl = tweetLink.href; | |
| 30 | ||
| 31 | tweetUrl = tweetUrl.replace('nitter.poast.org', 'twitter.com').replace('xcancel.com', 'twitter.com');
| |
| 32 | ||
| 33 | if (tweetUrl && tweetUrl.includes('/status/')) {
| |
| 34 | tweetUrl = tweetUrl.split('?')[0];
| |
| 35 | } | |
| 36 | - | tweetText = tweetText.replace(/ /g, ' '); |
| 36 | + | originalAuthorTweetUrls.push(tweetUrl); |
| 37 | - | |
| 37 | + | } else {
|
| 38 | ||
| 39 | var altTweetLink = tweet.querySelector('a[href*="/status/"]');
| |
| 40 | if (altTweetLink && !altTweetLink.querySelector('img')) {
| |
| 41 | var tweetUrl = altTweetLink.href; | |
| 42 | tweetUrl = tweetUrl.replace('nitter.poast.org', 'twitter.com').replace('xcancel.com', 'twitter.com');
| |
| 43 | if (tweetUrl && tweetUrl.includes('/status/')) {
| |
| 44 | tweetUrl = tweetUrl.split('?')[0];
| |
| 45 | } | |
| 46 | originalAuthorTweetUrls.push(tweetUrl); | |
| 47 | } | |
| 48 | } | |
| 49 | } | |
| 50 | }); | |
| 51 | ||
| 52 | console.log('Original author tweet URLs:', originalAuthorTweetUrls);
| |
| 53 | ||
| 54 | - | |
| 54 | + | |
| 55 | tweets.forEach(function(tweet, tweetIndex) {
| |
| 56 | var tweetAuthor = tweet.querySelector('.username');
| |
| 57 | if (tweetAuthor) {
| |
| 58 | var currentAuthor = tweetAuthor.textContent.slice(1); | |
| 59 | var tweetText = tweet.querySelector('.tweet-content').innerHTML;
| |
| 60 | tweetText = tweetText.replace(/<a[^>]+href="([^"]+)"[^>]*>@<[^<]+<\/a>/g, (match, p1) => `[U][URL]${p1}[/URL][/U]`);
| |
| 61 | tweetText = tweetText.replace(/<a[^>]+href="([^"]+)"[^>]*>[^<]+<\/a>/g, (match, p1) => `[U][URL]${p1}[/URL][/U]`);
| |
| 62 | tweetText = tweetText.replace(/<br>/g, '\n'); | |
| 63 | tweetText = tweetText.replace(/<span[^>]+data-sanitized-url="([^"]+)"[^>]*>[^<]+<\/span>/g, (match, p1) => `[U][URL]${p1}[/URL][/U]`);
| |
| 64 | tweetText = tweetText.replace(/<span[^>]+data-url="([^"]+)"[^>]*>[^<]+<\/span>/g, (match, p1) => `[U][URL]${p1}[/URL][/U]`);
| |
| 65 | tweetText = tweetText.replace(/<span[^>]+data-expanded-url="([^"]+)"[^>]*>[^<]+<\/span>/g, (match, p1) => `[U][URL]${p1}[/URL][/U]`);
| |
| 66 | tweetText = tweetText.replace(/<span[^>]+title="([^"]+)"[^>]*>[^<]+<\/span>/g, (match, p1) => `[U][URL]${p1}[/URL][/U]`);
| |
| 67 | tweetText = tweetText.replace(/<a[^>]+href="([^"]+)"[^>]*>[^<]+<\/a>/g, (match, p1) => `[U][URL]${p1}[/URL][/U]`);
| |
| 68 | tweetText = tweetText.replace(/]*>/g, '\n'); | |
| 69 | tweetText = tweetText.replace(/<[^>]+>/g, ''); | |
| 70 | - | |
| 70 | + | tweetText = tweetText.replace(/ /g, ' '); |
| 71 | ||
| 72 | var images = Array.from(tweet.querySelectorAll('.attachment.image img'));
| |
| 73 | - | tweetTexts.push({ text: tweetText, author: tweetAuthor.textContent.slice(1), index: globalTweetCount });
|
| 73 | + | |
| 74 | - | |
| 74 | + | |
| 75 | var url = new URL(src, window.location.href); | |
| 76 | url.hostname = 'pbs.twimg.com'; | |
| 77 | - | if (imgCounter >= 20 || tweet === tweets[tweets.length - 1]) {
|
| 77 | + | |
| 78 | - | if (userTweets.length > 0) {
|
| 78 | + | |
| 79 | - | var firstNewChainUrl = userTweets.shift(); |
| 79 | + | |
| 80 | - | var formattedText = `\n` + [ |
| 80 | + | |
| 81 | - | firstNewChainUrl, |
| 81 | + | |
| 82 | - | `[SPOILER="thread continued"]\n${userTweets.map(url => url.replace('nitter.poast.org', 'twitter.com').replace('xcancel.com', 'twitter.com')).map(url => {
|
| 82 | + | |
| 83 | - | if (url && url.includes('/status/')) {
|
| 83 | + | |
| 84 | - | return url.split('?')[0];
|
| 84 | + | |
| 85 | tweetText += `\n\n${imageUrlsForThisTweet}`;
| |
| 86 | - | return url; |
| 86 | + | |
| 87 | - | }).join('\n')}\n[/SPOILER]`,
|
| 87 | + | |
| 88 | - | `[SPOILER="full text & large images"]\n\n${tweetTexts.map((tweet, index) => `${globalTweetCount - tweetTexts.length + index + 1}/${globalTweetCount}\n@${tweet.author}\n${tweet.text}\n`).join('\n')}\n\n[COLOR=rgb(184, 49, 47)][B][SIZE=5]To post tweets in this format, more info here: [URL]https://www.thecoli.com/threads/tips-and-tricks-for-posting-the-coli-megathread.984734/post-52211196[/URL][/SIZE][/B][/COLOR]\n[/SPOILER]`
|
| 88 | + | |
| 89 | - | ].join('\n');
|
| 89 | + | |
| 90 | - | |
| 90 | + | |
| 91 | if (source && source.src) {
| |
| 92 | var src = source.src; | |
| 93 | - | userTweets = []; |
| 93 | + | |
| 94 | src = src.split('?')[0];
| |
| 95 | return `[U][URL]${src}[/URL][/U]`;
| |
| 96 | - | totalTweetCount = 0; |
| 96 | + | |
| 97 | } | |
| 98 | return ''; | |
| 99 | }).filter(url => url !== '').join('\n');
| |
| 100 | ||
| 101 | - | |
| 101 | + | |
| 102 | - | var finalFormattedText = ''; |
| 102 | + | |
| 103 | - | if (outputChains.length > 0) {
|
| 103 | + | |
| 104 | - | finalFormattedText = outputChains.join('\n\n');
|
| 104 | + | |
| 105 | globalTweetCount++; | |
| 106 | - | |
| 106 | + | |
| 107 | tweetTexts.push({
| |
| 108 | - | if (userTweets.length > 0) {
|
| 108 | + | text: tweetText, |
| 109 | - | var remainingFormattedText = `\n` + [ |
| 109 | + | author: currentAuthor, |
| 110 | - | userTweets[0].replace('nitter.poast.org', 'twitter.com').replace('xcancel.com', 'twitter.com'),
|
| 110 | + | index: globalTweetCount, |
| 111 | - | `[SPOILER="thread continued"]\n${userTweets.slice(1).map(url => url.replace('nitter.poast.org', 'twitter.com').replace('xcancel.com', 'twitter.com')).map(url => {
|
| 111 | + | isOriginalAuthor: (currentAuthor === originalAuthor) |
| 112 | - | if (url && url.includes('/status/')) {
|
| 112 | + | }); |
| 113 | - | return url.split('?')[0];
|
| 113 | + | |
| 114 | if (imgCounter >= 20 || tweetIndex === tweets.length - 1) {
| |
| 115 | - | return url; |
| 115 | + | if (tweetTexts.length > 0) {
|
| 116 | - | }).join('\n')}\n[/SPOILER]`,
|
| 116 | + | |
| 117 | - | `[SPOILER="full text & large images"]\n\n${tweetTexts.map((tweet, index) => `${globalTweetCount - tweetTexts.length + index + 1}/${globalTweetCount}\n@${tweet.author}\n${tweet.text}\n`).join('\n')}\n\n[COLOR=rgb(184, 49, 47)][B][SIZE=5]To post tweets in this format, more info here: [URL]https://www.thecoli.com/threads/tips-and-tricks-for-posting-the-coli-megathread.984734/post-52211196[/URL][/SIZE][/B][/COLOR]\n[/SPOILER]`
|
| 117 | + | var batchOriginalAuthorUrls = []; |
| 118 | - | ].join('\n');
|
| 118 | + | var currentBatchStartIndex = globalTweetCount - tweetTexts.length; |
| 119 | - | |
| 119 | + | |
| 120 | - | remainingFormattedText = remainingFormattedText.replace(/(\d+\/\d+)\s@/g, '$1\n@'); |
| 120 | + | |
| 121 | - | if (finalFormattedText) {
|
| 121 | + | tweetTexts.forEach((tweetObj, batchIndex) => {
|
| 122 | - | finalFormattedText += '\n\n[threads continued]\n\n' + remainingFormattedText; |
| 122 | + | if (tweetObj.isOriginalAuthor) {
|
| 123 | - | } else {
|
| 123 | + | var absoluteIndex = currentBatchStartIndex + batchIndex; |
| 124 | - | finalFormattedText = remainingFormattedText; |
| 124 | + | if (originalAuthorTweetUrls[absoluteIndex]) {
|
| 125 | batchOriginalAuthorUrls.push(originalAuthorTweetUrls[absoluteIndex]); | |
| 126 | - | } else if (tweetTexts.length > 0) {
|
| 126 | + | |
| 127 | - | |
| 127 | + | } |
| 128 | - | var remainingFormattedText = `\n` + [ |
| 128 | + | }); |
| 129 | - | window.location.href.replace('nitter.poast.org', 'twitter.com').replace('xcancel.com', 'twitter.com'),
|
| 129 | + | |
| 130 | - | `[SPOILER="full text & large images"]\n\n${tweetTexts.map((tweet, index) => `${globalTweetCount - tweetTexts.length + index + 1}/${globalTweetCount}\n@${tweet.author}\n${tweet.text}\n`).join('\n')}\n\n[COLOR=rgb(184, 49, 47)][B][SIZE=5]To post tweets in this format, more info here: [URL]https://www.thecoli.com/threads/tips-and-tricks-for-posting-the-coli-megathread.984734/post-52211196[/URL][/SIZE][/B][/COLOR]\n[/SPOILER]`
|
| 130 | + | var formattedText = ''; |
| 131 | - | ].join('\n');
|
| 131 | + | |
| 132 | - | |
| 132 | + | if (batchOriginalAuthorUrls.length > 1) {
|
| 133 | - | remainingFormattedText = remainingFormattedText.replace(/(\d+\/\d+)\s@/g, '$1\n@'); |
| 133 | + | |
| 134 | - | finalFormattedText = remainingFormattedText; |
| 134 | + | var firstTweetUrl = batchOriginalAuthorUrls[0]; |
| 135 | var remainingTweetUrls = batchOriginalAuthorUrls.slice(1); | |
| 136 | - | |
| 136 | + | |
| 137 | formattedText = `\n` + [ | |
| 138 | firstTweetUrl, | |
| 139 | `[SPOILER="thread continued"]\n${remainingTweetUrls.join('\n')}\n[/SPOILER]`,
| |
| 140 | `[SPOILER="full text & large images"]\n\n${tweetTexts.map((tweet, index) => `${globalTweetCount - tweetTexts.length + index + 1}/${globalTweetCount}\n@${tweet.author}\n${tweet.text}\n`).join('\n')}\n\n[COLOR=rgb(184, 49, 47)][B][SIZE=5]To post tweets in this format, more info here: [URL]https://www.thecoli.com/threads/tips-and-tricks-for-posting-the-coli-megathread.984734/post-52211196[/URL][/SIZE][/B][/COLOR]\n[/SPOILER]`
| |
| 141 | ].join('\n');
| |
| 142 | } else if (batchOriginalAuthorUrls.length === 1) {
| |
| 143 | - | |
| 143 | + | |
| 144 | formattedText = `\n` + [ | |
| 145 | batchOriginalAuthorUrls[0], | |
| 146 | `[SPOILER="full text & large images"]\n\n${tweetTexts.map((tweet, index) => `${globalTweetCount - tweetTexts.length + index + 1}/${globalTweetCount}\n@${tweet.author}\n${tweet.text}\n`).join('\n')}\n\n[COLOR=rgb(184, 49, 47)][B][SIZE=5]To post tweets in this format, more info here: [URL]https://www.thecoli.com/threads/tips-and-tricks-for-posting-the-coli-megathread.984734/post-52211196[/URL][/SIZE][/B][/COLOR]\n[/SPOILER]`
| |
| 147 | ].join('\n');
| |
| 148 | } else {
| |
| 149 | ||
| 150 | formattedText = `\n` + [ | |
| 151 | - | notificationBox.innerText = `Copied: ${globalTweetCount} tweets`;
|
| 151 | + | window.location.href.replace('nitter.poast.org', 'twitter.com').replace('xcancel.com', 'twitter.com'),
|
| 152 | `[SPOILER="full text & large images"]\n\n${tweetTexts.map((tweet, index) => `${globalTweetCount - tweetTexts.length + index + 1}/${globalTweetCount}\n@${tweet.author}\n${tweet.text}\n`).join('\n')}\n\n[COLOR=rgb(184, 49, 47)][B][SIZE=5]To post tweets in this format, more info here: [URL]https://www.thecoli.com/threads/tips-and-tricks-for-posting-the-coli-megathread.984734/post-52211196[/URL][/SIZE][/B][/COLOR]\n[/SPOILER]`
| |
| 153 | - | |
| 153 | + | ].join('\n');
|
| 154 | } | |
| 155 | ||
| 156 | formattedText = formattedText.replace(/(\d+\/\d+)\s@/g, '$1\n@'); | |
| 157 | outputChains.push(formattedText); | |
| 158 | ||
| 159 | imgCounter = 0; | |
| 160 | - | |
| 160 | + | |
| 161 | } | |
| 162 | } | |
| 163 | } | |
| 164 | }); | |
| 165 | ||
| 166 | var finalFormattedText = outputChains.join('\n\n');
| |
| 167 | ||
| 168 | var textArea = document.createElement('textarea');
| |
| 169 | textArea.value = finalFormattedText; | |
| 170 | document.body.appendChild(textArea); | |
| 171 | textArea.select(); | |
| 172 | document.execCommand('copy');
| |
| 173 | document.body.removeChild(textArea); | |
| 174 | ||
| 175 | var notificationBox = document.createElement('div');
| |
| 176 | notificationBox.style.position = 'fixed'; | |
| 177 | notificationBox.style.bottom = '20px'; | |
| 178 | notificationBox.style.left = '20px'; | |
| 179 | notificationBox.style.padding = '10px'; | |
| 180 | notificationBox.style.backgroundColor = 'white'; | |
| 181 | notificationBox.style.border = '1px solid black'; | |
| 182 | notificationBox.innerText = `Copied: ${globalTweetCount} tweets (Original: ${originalAuthor})`;
| |
| 183 | document.body.appendChild(notificationBox); | |
| 184 | ||
| 185 | setTimeout(function() {
| |
| 186 | notificationBox.style.opacity = '0'; | |
| 187 | setTimeout(function() {
| |
| 188 | document.body.removeChild(notificationBox); | |
| 189 | }, 1000); | |
| 190 | }, 2000); | |
| 191 | ||
| 192 | console.log('Tweet collection process completed and copied to clipboard.');
| |
| 193 | console.log('Original author tweet URLs found:', originalAuthorTweetUrls.length);
| |
| 194 | })(); |