tumblr.com Extra blog buttons

add extra navigation buttons to the upper left corner tumblr blogs

  1. // ==UserScript==
  2. // @name tumblr.com Extra blog buttons
  3. // @description add extra navigation buttons to the upper left corner tumblr blogs
  4. // @icon http://38.media.tumblr.com/avatar_fee7ff3e9d6a_48.png
  5. // @version 0.1.5
  6. // @license GNU General Public License v3
  7. // @copyright 2015, Nickel
  8. // @grant GM_addStyle
  9. // @include *://*.tumblr.com/*
  10. // @exclude *://*.tumblr.com/archive*
  11. // @exclude *://*.tumblr.com/image*
  12. // @exclude *://www.tumblr.com/*
  13. // @namespace https://greasyfork.org/users/10797
  14. // ==/UserScript==
  15.  
  16. /* TODO
  17. var foo = document.getElementById("tumblr_controls");
  18. window.getComputedStyle(foo, null).width
  19. */
  20.  
  21.  
  22. (function(){
  23.  
  24. // don't run in frames/iframes
  25. if( frameElement ){ return; }
  26. //if( window.self !== window.top ){ return; }
  27.  
  28. // don't run without tumblr elements
  29. if( (! document.getElementById('tumblr_controls')) && document.getElementsByClassName('tmblr-iframe').length==0 ){ return; }
  30.  
  31. // fallback (Chrome lacks GM functions)
  32. if( typeof GM_addStyle != 'function' ) {
  33. function GM_addStyle(css) {
  34. var head, style;
  35. head = document.getElementsByTagName('head')[0];
  36. if( !head ){ return; }
  37. style = document.createElement('style');
  38. style.type = 'text/css';
  39. style.innerHTML = css;
  40. head.appendChild(style);
  41. }
  42. }
  43.  
  44. // origin
  45. var origin = document.createElement("div");
  46. origin.id = "userscript-extra-buttons";
  47. document.body.appendChild(origin);
  48.  
  49. GM_addStyle("#userscript-extra-buttons {position:fixed; width:160px; height:20px; top:4px; left:5px; z-index:2147483647;}");
  50. GM_addStyle("#userscript-extra-buttons a {display:block; float:left; margin-right:3px; width:21px; height:100%; border-radius:2px; outline:0;}");
  51.  
  52. var splitUrl=window.location.href.split("/");
  53. var blogname = window.location.host.split(".")[0];
  54.  
  55. // add dash button (TODO: check if following/own blog)
  56. if ( splitUrl[3] == "post" ) {
  57. var pid = splitUrl[4];
  58. pid = Number(pid)+1;
  59.  
  60. var elm = document.createElement("a");
  61. elm.setAttribute( "style", "background:url(http://assets.tumblr.com/images/posts/nipple.png) repeat-x #222; width:28px;" );
  62. elm.href = "http://www.tumblr.com/dashboard/1000/" + pid + "?lite";
  63. elm.title = "Locate on Dashboard";
  64. origin.appendChild( elm );
  65. }
  66.  
  67. // add liked-by button (TODO: check if main blog)
  68. var elm = document.createElement("a");
  69. elm.setAttribute( "style", "background:url(http://assets.tumblr.com/images/iframe_like_alpha.png) no-repeat #222;" );
  70. elm.href = "http://www.tumblr.com/liked/by/" + blogname;
  71. elm.title = "Liked by " + blogname;
  72. origin.appendChild( elm );
  73.  
  74. // add archive button
  75. var elm = document.createElement("a");
  76. //elm.setAttribute( "style", "background:url(http://assets.tumblr.com/themes/redux/button-archive.png) no-repeat #222;" );
  77. elm.setAttribute( "style", "background:url(http://static.tumblr.com/vr9xgox/VT4nf8tvk/button-archive.png) no-repeat #222;" );
  78. elm.href = "http://" + blogname + ".tumblr.com/archive";
  79. elm.title = "Blog Archive";
  80. origin.appendChild( elm );
  81.  
  82. // add Home Button
  83. var elm = document.createElement("a");
  84. elm.setAttribute( "style", "background:url(http://assets.tumblr.com/images/iframe_dashboard_alpha.png) no-repeat #222;" );
  85. elm.href = "http://" + blogname + ".tumblr.com";
  86. elm.title = "Blog Home";
  87. origin.appendChild( elm );
  88.  
  89. // add prev/next page buttons
  90. var page = -1;
  91. var lastPage = 1000; // TODO
  92.  
  93. if( splitUrl[splitUrl.length-2] == "page" ){
  94. page = Number(splitUrl[splitUrl.length-1]);
  95. }
  96. else if( splitUrl[3] == "" || splitUrl[3] == "tagged" || splitUrl[3] == "search" ){
  97. page = 1;
  98. }
  99.  
  100. if( page > 1 ){
  101. var elm = document.createElement("a");
  102. elm.setAttribute( "style", "background:url(http://assets.tumblr.com/images/dashboard_controls_arrow_left.png) 50% no-repeat #222;" );
  103. elm.href = window.location.href.replace( /\/$/, "" ).replace( /\/page\/[0-9]+$/, "" ) + "/page/" + (page-1);
  104. elm.title = "prev page";
  105. origin.appendChild( elm );
  106. }
  107.  
  108. if( page > -1 && page < lastPage ){
  109. var elm = document.createElement("a");
  110. elm.setAttribute( "style", "background:url(http://assets.tumblr.com/images/dashboard_controls_arrow_right.png) 50% no-repeat #222;" );
  111. elm.href = window.location.href.replace( /\/$/, "" ).replace( /\/page\/[0-9]+$/, "" ) + "/page/" + (page+1);
  112. elm.title = "next page";
  113. origin.appendChild( elm );
  114.  
  115. var elm = document.createElement("a");
  116. elm.setAttribute( "style", "background:url(http://assets.tumblr.com/images/dashboard_controls_arrow_first_page.png) 50% no-repeat #222; width:24px; transform:scaleX(-1);" );
  117. elm.href = window.location.href.replace( /\/$/, "" ).replace( /\/page\/[0-9]+$/, "" ) + "/page/" + (page+10); //TODO: lastPage
  118. elm.title = "jump ahead 10 pages";
  119. origin.appendChild( elm );
  120. }
  121.  
  122. })();