Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- javascript:(function() {
- console.log('Nc6v3.4-3-fixed-universal');
- var tweets = Array.from(document.querySelectorAll('.timeline-item'));
- var tweetTexts = [];
- var userTweets = [];
- var imgCounter = 0;
- var globalTweetCount = 0;
- var totalTweetCount = 0;
- var outputChains = [];
- function universalizeUrl(url) {
- if (!url) return url;
- var urlStr = url.toString();
- var urlObj;
- try {
- urlObj = new URL(urlStr);
- if (urlObj.pathname.includes('/status/')) {
- urlObj.hostname = 'twitter.com';
- urlObj.protocol = 'https:';
- urlObj.search = '';
- return urlObj.href.split('?')[0];
- }
- return urlObj.href.split('?')[0];
- } catch (e) {
- if (urlStr.includes('/status/')) {
- var statusMatch = urlStr.match(/(\/status\/\d+)/);
- if (statusMatch) {
- return 'https://twitter.com' + statusMatch[1];
- }
- }
- return urlStr;
- }
- }
- var originalAuthor = null;
- var firstTweet = tweets[0];
- if (firstTweet) {
- var firstAuthor = firstTweet.querySelector('.username');
- if (firstAuthor) {
- originalAuthor = firstAuthor.textContent.slice(1);
- console.log('Original author identified:', originalAuthor);
- }
- }
- var originalAuthorTweetUrls = [];
- tweets.forEach(function(tweet) {
- var tweetAuthor = tweet.querySelector('.username');
- if (tweetAuthor && tweetAuthor.textContent.slice(1) === originalAuthor) {
- var tweetLink = tweet.querySelector('.tweet-link a') ||
- tweet.querySelector('.tweet-avatar + a') ||
- tweet.querySelector('a.tweet-link') ||
- tweet.querySelector('a[href*="/status/"]:not([href*="/photo/"])');
- if (tweetLink) {
- var tweetUrl = universalizeUrl(tweetLink.href);
- originalAuthorTweetUrls.push(tweetUrl);
- }
- }
- });
- console.log('Original author tweet URLs:', originalAuthorTweetUrls);
- tweets.forEach(function(tweet, tweetIndex) {
- var tweetAuthor = tweet.querySelector('.username');
- if (tweetAuthor) {
- var currentAuthor = tweetAuthor.textContent.slice(1);
- var tweetText = tweet.querySelector('.tweet-content').innerHTML;
- tweetText = tweetText.replace(/<a[^>]+href="([^"]+)"[^>]*>@<[^<]+<\/a>/g, (match, p1) => {
- var cleanUrl = universalizeUrl(p1);
- return `[U][URL]${cleanUrl}[/URL][/U]`;
- });
- tweetText = tweetText.replace(/<a[^>]+href="([^"]+)"[^>]*>[^<]+<\/a>/g, (match, p1) => {
- var cleanUrl = universalizeUrl(p1);
- return `[U][URL]${cleanUrl}[/URL][/U]`;
- });
- tweetText = tweetText.replace(/<br>/g, '\n');
- tweetText = tweetText.replace(/<span[^>]+data-sanitized-url="([^"]+)"[^>]*>[^<]+<\/span>/g, (match, p1) => {
- var cleanUrl = universalizeUrl(p1);
- return `[U][URL]${cleanUrl}[/URL][/U]`;
- });
- tweetText = tweetText.replace(/<span[^>]+data-url="([^"]+)"[^>]*>[^<]+<\/span>/g, (match, p1) => {
- var cleanUrl = universalizeUrl(p1);
- return `[U][URL]${cleanUrl}[/URL][/U]`;
- });
- tweetText = tweetText.replace(/<span[^>]+data-expanded-url="([^"]+)"[^>]*>[^<]+<\/span>/g, (match, p1) => {
- var cleanUrl = universalizeUrl(p1);
- return `[U][URL]${cleanUrl}[/URL][/U]`;
- });
- tweetText = tweetText.replace(/<span[^>]+title="([^"]+)"[^>]*>[^<]+<\/span>/g, (match, p1) => {
- var cleanUrl = universalizeUrl(p1);
- return `[U][URL]${cleanUrl}[/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: currentAuthor,
- index: globalTweetCount,
- isOriginalAuthor: (currentAuthor === originalAuthor)
- });
- if (imgCounter >= 20 || tweetIndex === tweets.length - 1) {
- if (tweetTexts.length > 0) {
- var batchOriginalAuthorUrls = [];
- var currentBatchStartIndex = globalTweetCount - tweetTexts.length;
- tweetTexts.forEach((tweetObj, batchIndex) => {
- if (tweetObj.isOriginalAuthor) {
- var absoluteIndex = currentBatchStartIndex + batchIndex;
- if (originalAuthorTweetUrls[absoluteIndex]) {
- batchOriginalAuthorUrls.push(originalAuthorTweetUrls[absoluteIndex]);
- }
- }
- });
- var formattedText = '';
- var currentPageUrl = universalizeUrl(window.location.href);
- if (batchOriginalAuthorUrls.length > 1) {
- var firstTweetUrl = batchOriginalAuthorUrls[0];
- var remainingTweetUrls = batchOriginalAuthorUrls.slice(1);
- formattedText = `\n` + [
- firstTweetUrl,
- `[SPOILER="thread continued"]\n${remainingTweetUrls.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');
- } else if (batchOriginalAuthorUrls.length === 1) {
- formattedText = `\n` + [
- batchOriginalAuthorUrls[0],
- `[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');
- } else {
- formattedText = `\n` + [
- currentPageUrl,
- `[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);
- imgCounter = 0;
- tweetTexts = [];
- }
- }
- }
- });
- var finalFormattedText = outputChains.join('\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 (Original: ${originalAuthor})`;
- 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.');
- console.log('Original author tweet URLs found:', originalAuthorTweetUrls.length);
- })();
Advertisement
Add Comment
Please, Sign In to add comment