Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- async function checkForReactions() {
- return new Promise((resolve, reject) => {
- try {
- var maxWaitReactionsTime = 10000;
- var reactions = document.evaluate(".//ul[contains(@class, 'uiList')]/li[div[text()]]", document, null, 7, null)
- // var button = document.evaluate(".//div/a[contains(@class, 'uiMorePagerPrimary')]", reactions.snapshotItem(0), null, 9, null).singleNodeValue;
- var reactionsInterval = setInterval(() => {
- reactions = document.evaluate(".//ul[contains(@class, 'uiList')]/li[div[text()]]", document, null, 7, null)
- if (maxWaitReactionsTime <= 0) {
- clearInterval(reactionsInterval);
- console.log('Time finished')
- resolve(reactions);
- }
- if (reactions) {
- clearInterval(reactionsInterval);
- console.log('reactions length ___' + reactions.snapshotLength)
- resolve(reactions);
- } else {
- maxWaitReactionsTime -= 500;
- console.log('Adding time...')
- }
- }, 500);
- } catch (error) {
- clearInterval(reactionsInterval);
- console.log(error.message);
- resolve(error.message || error)
- }
- })
- }
- async function proccessReactions(allReactions) {
- return new Promise(async (resolve, reject) => {
- try {
- var likesLimit = 50;
- var otherReactionsLimit = 20;
- var limit = 0;
- if (allReactions.snapshotLength > 0) {
- for (let i = 0; i < allReactions.snapshotLength; i++) {
- const currReaction = allReactions.snapshotItem(i);
- var reactionType = document.evaluate("./div[text()]", currReaction, null, 9, null).singleNodeValue;
- if (reactionType.textContent) {
- var reactionText = reactionType.textContent;
- console.log(reactionText);
- var clicking = await processSingleReactionByType(reactionText, currReaction);
- console.log(clicking)
- var reactiosByType = document.evaluate(".//ul/li[//a]", currReaction, null, 7, null)
- console.log(reactiosByType.snapshotLength);
- //if reactionsByType.snapshotLength;
- limit = reactionText === 'Like' ? likesLimit : otherReactionsLimit;
- console.log(limit)
- for (let j = 0; j < reactiosByType.snapshotLength; j++) {
- const el = reactiosByType.snapshotItem(j);
- if (j < limit) {
- var aTitle = document.evaluate(".//div[@class='clearfix']/a", el, null, 9, null).singleNodeValue;
- console.log(j)
- if(aTitle.getAttribute('title')) {
- console.log(aTitle.getAttribute('title') + ' ::: ' + reactionText)
- }
- // if(aTitle.getAttribute('ajaxify')) {
- // console.log(aTitle.getAttribute('ajaxify') + ' ::: ' + reactionText)
- // }
- // if(aTitle.getAttribute('data-hovercard')) {
- // console.log(aTitle.getAttribute('data-hovercard') + ' ::: ' + reactionText)
- // }
- } else {
- continue;
- }
- }
- } else {
- console.log('No text content for reaction type...');
- continue;
- }
- }
- } else {
- resolve('No reactions to collect')
- }
- } catch (e) {
- resolve(e.message || e)
- }
- })
- }
- async function processSingleReactionByType(type, reaction) {
- return new Promise((resolve, reject) => {
- try {
- var maxWaitReactionsTime = 10000;
- var counter = 0;
- // var reactions = document.evaluate(".//ul[contains(@class, 'uiList')]/li[div[text()]]", document, null, 7, null)
- var button = document.evaluate(".//div/a[contains(@class, 'uiMorePagerPrimary')]", reaction, null, 9, null).singleNodeValue;
- var buttonInterval = setInterval(() => {
- button = document.evaluate(".//div/a[contains(@class, 'uiMorePagerPrimary')]", reaction, null, 9, null).singleNodeValue;
- if (maxWaitReactionsTime <= 0) {
- clearInterval(buttonInterval);
- console.log('Time finished')
- resolve(true);
- }
- if (button) {
- if (counter >= 1) {
- clearInterval(buttonInterval);
- console.log('button clicked enough ___' + counter)
- resolve(true);
- } else {
- button.click();
- counter += 1;
- console.log('Clicking...')
- }
- } else {
- maxWaitReactionsTime -= 2000;
- console.log('Adding time...')
- }
- }, 2000);
- } catch (error) {
- clearInterval(buttonInterval);
- console.log(error.message);
- resolve(error.message || error)
- }
- })
- }
- async function startCollection() {
- var result = await checkForReactions();
- if (result && result.snapshotLength) {
- console.log(result.snapshotLength);
- await proccessReactions(result)
- } else {
- console.log('No reactions found!')
- return;
- //finalize();
- }
- }
- startCollection();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement