liveweird
2/13/2016 - 3:08 PM

twitter_helper.js

// ==UserScript==
// @name         Twitter Helper
// @namespace    http://gebski.tech/
// @version      0.1
// @description  Makes Twitter more approachable
// @author       http://gebski.tech/
// @require      https://cdnjs.cloudflare.com/ajax/libs/babel-core/5.6.15/browser-polyfill.min.js
// @require      https://cdnjs.cloudflare.com/ajax/libs/babel-core/5.6.15/browser.min.js
// @require      https://code.jquery.com/jquery-latest.js
// @match        https://twitter.com/
// ==/UserScript==

/* jshint ignore:start */
var inline_src = (<><![CDATA[
/* jshint ignore:end */
/* jshint esnext:true */

$.fn.goTo = function() {
    // $(this).scrollIntoView();
    $('html, body').animate({
      scrollTop: $(this).offset().top + 'px'
    }, 'fast');
    return this;
}    
    
var magic = $("<button id=\"magic-button-id\">Magic</button>");
magic.css({"position": "absolute", "top": "30px", "left": "20px", "z-index": 100});

magic.click(function () {
  // mark element
  var top_item_id = $("#stream-items-id li.stream-item").first().attr("id");
  var top_item = $("#" + top_item_id);
  top_item.css({"background-color": "red"});    
  // refresh twitter
  var refresh = $("div.new-tweets-bar");
  if(typeof refresh ==='object' && refresh instanceof Array && !refresh.length) {
    return;
  }
  refresh.click();
  // jump to marked
  top_item.goTo();
});
  
var dashboard = $("div#doc");
dashboard.children().prepend(magic);
    
/* jshint ignore:start */
]]></>).toString();
var c = babel.transform(inline_src);
eval(c.code);
/* jshint ignore:end */