Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- javascript:(function() {
- console.log('Nc6v3.4-2');
- var tweets = Array.from(document.querySelectorAll('.timeline-item'));
- var tweetTexts = [];
- var userTweets = [];
- var imgCounter = 0;
- var globalTweetCount = 0;
- var totalTweetCount = 0;
- var outputChains = [];
- tweets.forEach(function(tweet) {
- var tweetAuthor = tweet.querySelector('.username');
- if (tweetAuthor) {
- var tweetText = tweet.querySelector('.tweet-content').innerHTML;
- tweetText = tweetText.replace(/<a[^>]+href="([^"]+)"[^>]*>@<[^<]+<\/a>/g, (match, p1) => `[U][URL]${p1}[/URL][/U]`);
- tweetText = tweetText.replace(/<a[^>]+href="([^"]+)"[^>]*>[^<]+<\/a>/g, (match, p1) => `[U][URL]${p1}[/URL][/U]`);
- tweetText = tweetText.replace(/<br>/g, '\n');
- tweetText = tweetText.replace(/<span[^>]+data-sanitized-url="([^"]+)"[^>]*>[^<]+<\/span>/g, (match, p1) => `[U][URL]${p1}[/URL][/U]`);
- tweetText = tweetText.replace(/<span[^>]+data-url="([^"]+)"[^>]*>[^<]+<\/span>/g, (match, p1) => `[U][URL]${p1}[/URL][/U]`);
- tweetText = tweetText.replace(/<span[^>]+data-expanded-url="([^"]+)"[^>]*>[^<]+<\/span>/g, (match, p1) => `[U][URL]${p1}[/URL][/U]`);
- tweetText = tweetText.replace(/<span[^>]+title="([^"]+)"[^>]*>[^<]+<\/span>/g, (match, p1) => `[U][URL]${p1}[/URL][/U]`);
- tweetText = tweetText.replace(/<a[^>]+href="([^"]+)"[^>]*>[^<]+<\/a>/g, (match, p1) => `[U][URL]${p1}[/URL][/U]`);
- tweetText = tweetText.replace(/]*>/g, '\n');
- tweetText = tweetText.replace(/<[^>]+>/g, '');
- tweetText = tweetText.replace(/Β /g, ' ');
- var images = Array.from(tweet.querySelectorAll('.attachment.image img'));
- var imageUrlsForThisTweet = images.map(img => {
- var src = decodeURIComponent(img.src);
- var url = new URL(src, window.location.href);
- url.hostname = 'pbs.twimg.com';
- url.pathname = url.pathname.replace('/pic/', '/media/').replace('/media/media/', '/media/');
- url.pathname = url.pathname.replace(/\/media\/.*\/media\//, '/media/');
- url.search = '';
- return `[img]${url.href}[/img]`;
- }).join('\n');
- imgCounter += images.length;
- if (imageUrlsForThisTweet) {
- tweetText += `\n\n${imageUrlsForThisTweet}`;
- }
- var videos = Array.from(tweet.querySelectorAll('video'));
- var videoUrlsForThisTweet = videos.map(video => {
- var source = video.querySelector('source');
- if (source && source.src) {
- var src = source.src;
- if (src && (src.startsWith('https://video') && (src.includes('twimg.com/ext_tw_video/') || src.includes('twimg.com/amplify_video/')))) {
- src = src.split('?')[0];
- return `[U][URL]${src}[/URL][/U]`;
- }
- }
- return '';
- }).filter(url => url !== '').join('\n');
- if (videoUrlsForThisTweet) {
- tweetText += `\n\n${videoUrlsForThisTweet}`;
- }
- globalTweetCount++;
- totalTweetCount++;
- tweetTexts.push({ text: tweetText, author: tweetAuthor.textContent.slice(1), index: globalTweetCount });
- if (imgCounter >= 20 || tweet === tweets[tweets.length - 1]) {
- if (userTweets.length > 0) {
- var firstNewChainUrl = userTweets.shift();
- var formattedText = `\n` + [
- firstNewChainUrl,
- `[SPOILER="thread continued"]\n${userTweets.map(url => url.replace('nitter.poast.org', 'twitter.com').replace('xcancel.com', 'twitter.com')).map(url => {
- if (url && url.includes('/status/')) {
- return url.split('?')[0];
- }
- return url;
- }).join('\n')}\n[/SPOILER]`,
- `[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]`
- ].join('\n');
- formattedText = formattedText.replace(/(\d+\/\d+)\s@/g, '$1\n@');
- outputChains.push(formattedText);
- userTweets = [];
- imgCounter = 0;
- tweetTexts = [];
- totalTweetCount = 0;
- }
- }
- }
- });
- var finalFormattedText = '';
- if (outputChains.length > 0) {
- finalFormattedText = outputChains.join('\n\n');
- }
- if (userTweets.length > 0) {
- var remainingFormattedText = `\n` + [
- userTweets[0].replace('nitter.poast.org', 'twitter.com').replace('xcancel.com', 'twitter.com'),
- `[SPOILER="thread continued"]\n${userTweets.slice(1).map(url => url.replace('nitter.poast.org', 'twitter.com').replace('xcancel.com', 'twitter.com')).map(url => {
- if (url && url.includes('/status/')) {
- return url.split('?')[0];
- }
- return url;
- }).join('\n')}\n[/SPOILER]`,
- `[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]`
- ].join('\n');
- remainingFormattedText = remainingFormattedText.replace(/(\d+\/\d+)\s@/g, '$1\n@');
- if (finalFormattedText) {
- finalFormattedText += '\n\n[threads continued]\n\n' + remainingFormattedText;
- } else {
- finalFormattedText = remainingFormattedText;
- }
- } else if (tweetTexts.length > 0) {
- var remainingFormattedText = `\n` + [
- window.location.href.replace('nitter.poast.org', 'twitter.com').replace('xcancel.com', 'twitter.com'),
- `[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]`
- ].join('\n');
- remainingFormattedText = remainingFormattedText.replace(/(\d+\/\d+)\s@/g, '$1\n@');
- finalFormattedText = remainingFormattedText;
- }
- var textArea = document.createElement('textarea');
- textArea.value = finalFormattedText;
- document.body.appendChild(textArea);
- textArea.select();
- document.execCommand('copy');
- document.body.removeChild(textArea);
- var notificationBox = document.createElement('div');
- notificationBox.style.position = 'fixed';
- notificationBox.style.bottom = '20px';
- notificationBox.style.left = '20px';
- notificationBox.style.padding = '10px';
- notificationBox.style.backgroundColor = 'white';
- notificationBox.style.border = '1px solid black';
- notificationBox.innerText = `Copied: ${globalTweetCount} tweets`;
- document.body.appendChild(notificationBox);
- setTimeout(function() {
- notificationBox.style.opacity = '0';
- setTimeout(function() {
- document.body.removeChild(notificationBox);
- }, 1000);
- }, 2000);
- console.log('Tweet collection process completed and copied to clipboard.');
- })();
Advertisement
Add Comment
Please, Sign In to add comment