Last active
June 27, 2019 15:57
-
-
Save shakkurcwb/21d6b630d3dd49f74a3f5807d3dc88b7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* This script add new buttons into LinkedIn post page. | |
* (open all comments, read all comments, like all comments). | |
* | |
* 1 - Open a Post Page on LinkedIn (URL like "/feed/update/"); | |
* 2 - Copy and Paste this code into your Browser Console Tab, then press ENTER. | |
* | |
* Be polite when using it. I am not responsible for bad usage! | |
* | |
* @author ma.ferreira93@gmail.com | |
*/ | |
var dataset = []; | |
function done() { | |
scrollTo($('.feed-shared-actor')); | |
$(document).off("click", "#show_prev"); | |
alert("Todos os comentarios foram abertos e lidos. Clique em Resumir Todos para compilar."); | |
} | |
function initRadar() { | |
var p = new Promise(function(resolve, reject) { resolve(); }); | |
p.then(loadPreviousReplies); | |
p.then(loadMoreComments); | |
} | |
function loadPreviousReplies() { | |
var buttonCollection = $('.show-prev-replies'); | |
handleClick(buttonCollection); | |
console.log('loadPreviousReplies clicked'); | |
} | |
function loadMoreComments() { | |
var buttonCollection = $('#show_prev'); | |
if (buttonCollection.length > 0) { | |
handleClick(buttonCollection); | |
console.log('loadMoreComments clicked'); | |
} else done(); | |
} | |
function scrollTo(element) { | |
$([document.documentElement, document.body]).animate({ | |
scrollTop: $(element).offset().top | |
}, 100); | |
} | |
function handleClick(buttonCollection) { | |
if (buttonCollection && buttonCollection.length > 0) { | |
for (var i=0; i<buttonCollection.length; i++) { | |
click(buttonCollection[i]); | |
} | |
} | |
} | |
function click(button) { | |
scrollTo(button); | |
button.click(); | |
} | |
function beforeReader() { | |
console.clear(); | |
dataset = []; | |
} | |
function afterReader() { | |
alert("Dados Coletados. Exibindo no Console."); | |
console.log(dataset); | |
} | |
function initReader() { | |
console.log('reader'); | |
beforeReader(); | |
var articlesCollection = $("article"); | |
for (var i=0; i<articlesCollection.length; i++) { | |
dataset.push(extractCommentDetails(articlesCollection[i])); | |
} | |
afterReader(); | |
} | |
function extractCommentDetails(element) { | |
var metaActor = element.querySelector(".feed-shared-post-meta__actor"); | |
var metaName = metaActor.querySelector(".feed-shared-post-meta__name"); | |
var metaHeadline = metaActor.querySelector(".feed-shared-post-meta__headline"); | |
var mainContent = element.querySelector(".comments-comment-item__main-content"); | |
var isChild = element.classList.contains("comments-reply-item"); | |
return { | |
_isRoot: !isChild, | |
name: metaName.innerText, | |
title: metaHeadline.innerText, | |
comment: mainContent.innerText, | |
_dom: element, | |
}; | |
} | |
function showUserOptions() { | |
$('.social-details-social-counts').append(` | |
<li class="social-details-social-counts__item"> | |
<button ID="RADAR" class="social-details-social-counts__count-value t-12 t-black--light t-normal hoverable-link-text"> | |
<span aria-hidden="true" class="v-align-middle">Ler Todos</span> | |
</button> | |
</li> | |
`); | |
$('.social-details-social-counts').append(` | |
<li class="social-details-social-counts__item"> | |
<button ID="READER" class="social-details-social-counts__count-value t-12 t-black--light t-normal hoverable-link-text"> | |
<span aria-hidden="true" class="v-align-middle">Resumir Todos</span> | |
</button> | |
</li> | |
`); | |
$('.social-details-social-counts').append(` | |
<li class="social-details-social-counts__item"> | |
<button ID="LIKER" class="social-details-social-counts__count-value t-12 t-black--light t-normal hoverable-link-text"> | |
<span aria-hidden="true" class="v-align-middle">Curtir Todos</span> | |
</button> | |
</li> | |
`); | |
} | |
function initLiker() { | |
if (dataset && dataset.length > 0) { | |
$.each(Object.keys(dataset), function(id) { | |
likeComment(id); | |
}); | |
alert(`${dataset.length} comentarios curtidos!`); | |
} else { | |
alert('Clique em RESUMIR TODOS primeiro!'); | |
} | |
} | |
function likeComment(id = null) { | |
var data = dataset[id]; | |
if (data) { | |
var button = data._dom.querySelector(".comments-comment-social-bar__like-action-button"); | |
if (!button.classList.contains("active")) { | |
button.click(); | |
} | |
} | |
} | |
function initListeners() { | |
$(document).on("click", "#RADAR", initRadar); | |
$(document).on("click", "#READER", initReader); | |
$(document).on("click", "#LIKER", initLiker); | |
$(document).on("click", "#show_prev", function() { | |
setTimeout(initRadar, 2500); | |
}); | |
} | |
showUserOptions(); | |
initListeners(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment