Skip to content

Instantly share code, notes, and snippets.

@lmmx
Last active August 29, 2015 13:57
Show Gist options
  • Save lmmx/9852222 to your computer and use it in GitHub Desktop.
Save lmmx/9852222 to your computer and use it in GitHub Desktop.
var tweets; var msg; var sansLink = []; var sansDesc = []; var badTweets = []; var badParents = [];
function article(desc,aURL) { this.desc=desc; this.aURL=aURL; }
function BadApples() {
tweets = document.querySelectorAll(".js-stream-item div .js-tweet-text");
msg = []; sansLink = []; sansDesc = [];
document.querySelector(".ProfilePhotoRail-mediaBox").remove();
for (i=0;i<tweets.length;i++) {
var sub = tweets[i].childNodes;
if (sub[0].tagName == "A") {
msg.push(new article(null,sub[0].getAttribute('data-expanded-url')));
sansDesc.push(i); }
if (tweets[i].innerHTML == tweets[i].textContent) {
msg.push(new article(tweets[i].textContent.replace(/\n/g,' '),null));
sansLink.push(i); }}
badTweets = [];
var llen = sansLink.length;
var dlen = sansDesc.length;
for (k=0;k<llen;k++) {
badTweets.push(tweets[sansLink[k]]); }
for (m=0;m<dlen;m++) {
badTweets.push(tweets[sansDesc[m]]); }
badParents = [];
for (y=0;y<badTweets.length;y++) {
badParents.push(badTweets[y].parentNode.parentNode.parentNode.parentNode); }
var stream = document.querySelector('.GridTimeline-items').parentNode;
var timeline = stream.parentNode;
var newList = document.createElement('div');
for (x=0;x<badParents.length;x++) {
newList.appendChild(badParents[x]); }
timeline.replaceChild(newList,stream); }
BadApples();
$('button[type="button"][class="ProfileTweet-actionButton u-linkPseudo js-actionDelete js-tooltip"]').each(function(d, x){
$(x).trigger('click')
$('button[class="btn primary-btn delete-action"]').trigger('click');
})
// paste value of msg at naivelocus.com since CORS isn't gonna play ball with proprietary frigging XML headers
if (typeof msg === "undefined") {newTweets = prompt("Paste msg here then copy ′newTweets′");}
for (i=0;i<msg.length;i++) {
if (msg[i].desc === null) {
NLurls = document.querySelectorAll('#content > article > div > p > a');
for (j=0;j<NLurls.length;j++) {
if (NLurls[j].href == msg[i].aURL) {
msg[i].desc = NLurls[j].parentNode.parentNode.childNodes[1].textContent; }
else { var SDcode = "article/pii/";
if (NLurls[j].href.indexOf(SDref) != -1) {
var SDref = msg[i].aURL.substr(msg[i].aURL.indexOf(SDcode)+SDcode.length);
if (NLurls[j].href.match(SDref) !== null) {
msg[i].desc = NLurls[j].parentNode.parentNode.childNodes[1].textContent; }}}}}
if (msg[i].aURL === null) {
if (msg[i].desc[msg[i].desc.length-1] == " ") {
msg[i].desc = msg[i].desc.substr(0,msg[i].desc.length-1); }
if (msg[i].desc.substr(msg[i].desc.length-4) == " ...") {
msg[i].desc = msg[i].desc.substr(0,msg[i].desc.length-4); }
NLtitles = document.querySelectorAll('h3#head');
for (j=0;j<NLtitles.length;j++) {
console.log(j+","+i);
if (NLtitles[j].textContent.replace(/\n/g,' ') == msg[i].desc) {
for (k=1;k<NLtitles[j].parentNode.querySelectorAll('a').length;k++) {
if (NLtitles[j].parentNode.querySelectorAll('a')[k].previousSibling !== null) {
if (NLtitles[j].parentNode.querySelectorAll('a')[k].previousSibling.textContent.match("— ") !== null) {
var piiStart = "piikey%3D";
var piiEnd = "%26_version";
var prefix = "http://www.sciencedirect.com/science/article/pii/";
if (NLtitles[j].parentNode.querySelectorAll('a')[k].href.indexOf(piiStart) != -1) {
var urlName = NLtitles[j].parentNode.querySelectorAll('a')[k].href;
var startN = urlName.indexOf(piiStart)+piiStart.length;
var endN = urlName.indexOf(piiEnd);
var SDref = urlName.substr(startN,endN-startN);
if (urlName.match(SDref) !== null) {
msg[i].aURL = prefix+SDref; }}
else msg[i].aURL = NLtitles[j].parentNode.querySelectorAll('a')[k].href; }}}}}}}
newTweets = [];
for (i=0;i<msg.length;i++) { newTweets.push(msg[i].desc+" "+msg[i].aURL); }
// paste newTweets back into the Twitter window, or else
if (typeof newTweets === "undefined") {newTweets = prompt("Paste them here");}
if (typeof t === "undefined") {t=0;}
$('span[class="Icon Icon--tweet Icon--large"]').trigger('click');
$('div[id="tweet-box-global"]')[0].innerHTML = newTweets[t];
$('button[class="btn primary-btn tweet-action tweet-btn js-tweet-btn"]').trigger('click');
if (t<newTweets.length) {t++;} else console.log("That's all!");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment