Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- javascript:(function() {
- var isXstalk = window.location.hostname.includes('xstalk.com') || window.location.hostname.includes('twstalker.com');
- var tweetSelector = isXstalk ? '.tweet-container' : '.timeline-item';
- var contentSelector = isXstalk ? '.tweet-body' : '.tweet-content';
- var usernameSelector = isXstalk ? '.tweet-container .profile-link a span' : '.username';
- var tweetLinkSelector = isXstalk ? '.tweet-container .profile-link a[href*="/status/"]' : '.tweet-link';
- var authorSelector = isXstalk ? '.tweet-container .profile-link span' : '.username';
- var imageSelector = isXstalk ? '.tweet-images img, .tweet-video video[poster]' : '.attachment.image img';
- var videoSelector = isXstalk ? '.tweet-video video' : 'video';
- var tweets = Array.from(document.querySelectorAll(tweetSelector));
- if (tweets.length === 0) {
- tweets = Array.from(document.querySelectorAll('.timeline-item, .tweet-container'));
- if (tweets.length === 0) return;
- }
- var username = document.querySelector(usernameSelector);
- if (!username) {
- username = document.querySelector('.username, .tweet-container .profile-link span');
- if (!username) return;
- }
- username = username.textContent.replace('@', '').trim();
- var userTweets = [];
- var tweetTexts = [];
- var imgCounter = 0;
- var outputChains = [];
- var totalTweetCount = 0;
- var globalTweetCount = 0;
- function replaceDomain(url) {
- return url.replace('nitter.poast.org', 'twitter.com').replace('xcancel.com', 'twitter.com').replace('xstalk.com', 'twitter.com').replace('twstalker.com', 'twitter.com');
- }
- var currentUrl = replaceDomain(window.location.href);
- if (currentUrl.includes('/status/')) {
- currentUrl = currentUrl.split('?')[0];
- userTweets.push(currentUrl);
- }
- tweets.forEach(tweet => {
- var tweetLink = tweet.querySelector(tweetLinkSelector);
- var tweetAuthor = tweet.querySelector(authorSelector);
- if (tweetLink && tweetAuthor) {
- var tweetLinkHref = new URL(tweetLink.href, window.location.href);
- var newUrl = replaceDomain(tweetLinkHref.href);
- if (newUrl && newUrl.includes('/status/')) {
- newUrl = newUrl.split('?')[0];
- }
- var authorName = tweetAuthor.textContent.replace('@', '').trim();
- if (newUrl && newUrl.includes('/status/') && authorName === username) {
- userTweets.push(newUrl);
- }
- }
- var tweetContent = tweet.querySelector(contentSelector);
- if (!tweetContent && isXstalk) {
- tweetContent = tweet.querySelector('.tweet-body');
- }
- if (tweetContent) {
- var tweetText = tweetContent.innerHTML;
- var quotedTweets = Array.from(tweet.querySelectorAll('.quote.quote-big, .quote'));
- var quotedTextForThisTweet = quotedTweets.map(quotedTweet => {
- var quoteTextElement = quotedTweet.querySelector('.quote-text, .tweet-body');
- var quoteUrlElement = quotedTweet.querySelector('.quote-link, a[href*="/status/"]');
- if (quoteTextElement && quoteUrlElement) {
- var quoteText = quoteTextElement.textContent;
- var quoteUrl = quoteUrlElement.href;
- var quoteUrlObj = new URL(quoteUrl, window.location.href);
- quoteUrlObj.hostname = 'twitter.com';
- return `[Quoted tweet]\n${quoteText}\n[U][URL]${quoteUrlObj.href}[/URL][/U]`;
- }
- return '';
- }).filter(text => text !== '').join('\n\n');
- tweetText += `\n\n${quotedTextForThisTweet}`;
- tweetText = tweetText.replace(/<a href="([^"]+)">[^<]+<\/a>/g, (match, p1) => `[U][URL]${p1}[/URL][/U]`);
- tweetText = tweetText.replace(/<br[^>]*>/g, '\n');
- tweetText = tweetText.replace(/<[^>]+>/g, '');
- tweetText = tweetText.replace(/Β /g, ' ');
- tweetText = tweetText.trim();
- var images = Array.from(tweet.querySelectorAll(imageSelector));
- var imageUrlsForThisTweet = images.map(img => {
- var src = decodeURIComponent(img.src || img.getAttribute('poster') || '');
- if (!src) return '';
- var url = new URL(src, window.location.href);
- if (url.hostname.includes('xcancel.com') && url.pathname.includes('/pic/')) {
- var pathParts = url.pathname.split('/');
- var mediaPart = pathParts[pathParts.length - 1];
- var decodedMedia = decodeURIComponent(mediaPart);
- var filename = decodedMedia.split('?')[0];
- var match = filename.match(/([^\/]+)$/);
- if (match) {
- return `[img]https://pbs.twimg.com/media/${match[1]}[/img]`;
- }
- }
- if (src.includes('pbs.twimg.com') && (src.includes('ext_tw_video_thumb') || src.includes('media'))) {
- var posterMatch = src.match(/\/([^\/]+)\.(jpg|png|webp)/);
- if (posterMatch) {
- return `[img]https://pbs.twimg.com/media/${posterMatch[1]}.${posterMatch[2]}[/img]`;
- }
- }
- url.hostname = 'pbs.twimg.com';
- url.pathname = url.pathname.replace('/pic/', '/media/').replace('/media/media/', '/media/');
- url.search = '';
- return `[img]${url.href}[/img]`;
- }).filter(url => url !== '').join('\n');
- if (imgCounter + images.length > 20 && tweetTexts.length > 0) {
- createChain();
- }
- imgCounter += images.length;
- if (imageUrlsForThisTweet) {
- tweetText += `\n\n${imageUrlsForThisTweet}`;
- }
- var videos = Array.from(tweet.querySelectorAll(videoSelector));
- var videoUrlsForThisTweet = videos.map(video => {
- var source = video.querySelector('source');
- var src = source ? source.src : video.src;
- if (!src) return '';
- 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++;
- var authorName = tweetAuthor ? tweetAuthor.textContent.replace('@', '').trim() : username;
- tweetTexts.push({ text: tweetText.trim(), author: authorName, index: globalTweetCount });
- }
- });
- if (tweetTexts.length > 0) {
- createChain();
- }
- function createChain() {
- if (userTweets.length === 0) return;
- var firstNewChainUrl = userTweets.shift();
- var formattedText = `\n` + [
- firstNewChainUrl,
- `[SPOILER="thread continued"]\n${userTweets.map(url => replaceDomain(url)).map(url => {
- return url.includes('/status/') ? url.split('?')[0] : url;
- }).join('\n')}\n[/SPOILER]`,
- `[SPOILER="full text & large images"]\n\n${tweetTexts.map((tweet, index) =>
- `${index + 1}/${tweetTexts.length}\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);
- imgCounter = 0;
- tweetTexts = [];
- totalTweetCount = 0;
- }
- var finalFormattedText = outputChains.join('\n\n[threads continued]\n\n');
- 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