Last.fm - Hide Activity Box

Allows user to toggle display of activity box in their own profile

  1. // ==UserScript==
  2. // @name Last.fm - Hide Activity Box
  3. // @namespace http://no.name.space/
  4. // @description Allows user to toggle display of activity box in their own profile
  5. // @include http://www.last.fm/user/*
  6. // @include http://www.last.fm/place/*
  7. // @include http://www.last.fm/music/*
  8. // @include http://www.last.fm/home
  9. // @include http://www.lastfm.fr/user/*
  10. // @include http://www.lastfm.fr/music/*
  11. // @include http://www.lastfm.fr/place/*
  12. // @include http://www.lastfm.de/user/*
  13. // @include http://www.lastfm.de/music/*
  14. // @include http://www.lastfm.de/place/*
  15. // @include http://www.lastfm.es/user/*
  16. // @include http://www.lastfm.es/music/*
  17. // @include http://www.lastfm.es/place/*
  18. // @include http://www.lastfm.se/user/*
  19. // @include http://www.lastfm.it/user/*
  20. // @include http://www.lastfm.it/music/*
  21. // @exclude http://www.lastfm.se/music/*
  22. // @include http://www.lastfm.se/place/*
  23. // @include http://www.lastfm.com.br/user/*
  24. // @exclude http://www.lastfm.com.br/music/*
  25. // @include http://www.lastfm.com.br/place/*
  26. // @exclude http://www.last.fm/user/*/*
  27. // @exclude http://www.lastfm.fr/user/*/*
  28. // @exclude http://www.lastfm.de/user/*/*
  29. // @exclude http://www.lastfm.it/user/*/*
  30. // @exclude http://www.lastfm.es/user/*/*
  31. // @exclude http://www.lastfm.se/user/*/*
  32. // @exclude http://www.lastfm.com.br/user/*/*
  33. // @version 0.0.1.20140511024434
  34. // ==/UserScript==
  35.  
  36. // 26-Jul-2008 created snyde1
  37. // 26-Sep-2008 update for more pages, languages
  38.  
  39. function xpath(query) {
  40. return document.evaluate(query, document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
  41. }
  42. function drudgeWork (myNode, myId, myKey) {
  43. if (!document.getElementById(myId)) {
  44. myNode.nextSibling.nextSibling.setAttribute("id",myId);
  45. }
  46. var myTempStr = "<A style=\"color: #D51007;\" HREF=\"javascript:(hydeSnyde('"+myId+"','"+myKey+"'))\">+/&ndash;</A> / ";
  47. if (myId != "player") {
  48. myNode.firstChild.innerHTML = myTempStr + myNode.firstChild.innerHTML;
  49. }
  50. if(document.cookie.match(/HydeVSJekyll=/)) {
  51. var oldCookie = document.cookie.match(/HydeVSJekyll=([^;]*)[;$]/)[1];
  52. var keyThere = new RegExp(myKey);
  53. if (oldCookie.match(keyThere)) {
  54. document.getElementById(myId).setAttribute('style','display: none; visibility: hidden;');
  55. }
  56. } else {
  57. var myDte = new Date((new Date()).getTime() + (2*365*24*3600*1000));
  58. var myStr = "HydeVSJekyll=RA; "+"expires="+myDte.toGMTString();
  59. document.cookie = myStr;
  60. }
  61. }
  62. function getLastfmUsername() {
  63. var usernameLink = xpath("//a[contains(@class,'user-badge')]");
  64. if (usernameLink.snapshotLength > 0) {
  65. return(usernameLink.snapshotItem(1).innerHTML);
  66. } else {
  67. usernameLink = xpath("//a[@id='idBadgerUser']");
  68. if (usernameLink.snapshotLength > 0) {
  69. var userNameLoc = usernameLink.snapshotItem(0).innerHTML;
  70. userNameLoc = userNameLoc.replace(/<[^<>]*>/g,"").replace(/^\s*/m,"").replace(/\s*$/,"");
  71. return(userNameLoc);
  72. } else {
  73. return("");
  74. }
  75. }
  76. }
  77. (function () {
  78. // username = getLastfmUsername();
  79. // if (username == "") { return; }
  80. // var re2 = new RegExp("\/"+username+"$", "i"); // Is it my page or another's?
  81. // if (! location.href.match(re2)) { return; }
  82.  
  83. // Matches for English
  84. var raRE = new RegExp(/Recent Activity/i);
  85. var rvRE = new RegExp(/Recent Visitors/i);
  86. var amRE = new RegExp(/About Me/i);
  87. var frRE = new RegExp(/Friends/);
  88. var lbfrRE = new RegExp(/(Your friends in common|You are connected through)/);
  89. var arRE = new RegExp(/Journals/i);
  90. var grRE = new RegExp(/Groups/i);
  91. var evRE = new RegExp(/Events/i);
  92. var neRE = new RegExp(/Neighbours/i);
  93. var libRE = new RegExp(/ Library/i);
  94. var retRE = new RegExp(/Recently Listened Tracks/i);
  95. var sbRE = new RegExp(/ShoutBox/i);
  96. var taRE = new RegExp(/Top Artists/i);
  97. var ttRE = new RegExp(/Top Tracks/i);
  98. var talRE = new RegExp(/Top Albums/i);
  99. var rarRE = new RegExp(/Related Journals/i);
  100. var pliRE = new RegExp(/More Information/i);
  101. var liRE = new RegExp(/Top Listeners/i);
  102. var lnRE = new RegExp(/Listening Now/i);
  103. var ltRE = new RegExp(/Listening Trend/i);
  104. var emnRE = new RegExp(/Email Newsletter/i);
  105. var simRE = new RegExp(/Similar/i);
  106. var vidRE = new RegExp(/Videos/i);
  107. // for French
  108. if (location.href.match(/www.lastfm.fr/i)) {
  109. raRE = new RegExp(/Activit. r.cente/i);
  110. rvRE = new RegExp(/Visiteurs r.cents/i);
  111. amRE = new RegExp(/propos de moi/i);
  112. frRE = new RegExp(/Amis/);
  113. lbfrRE = new RegExp(/(Vos amis en commun|Vous .tes connect. via)/);
  114. arRE = new RegExp(/Articles/i);
  115. grRE = new RegExp(/Groupes/i);
  116. evRE = new RegExp(/Concerts/i);
  117. neRE = new RegExp(/Voisins/i);
  118. libRE = new RegExp(/Biblioth.que de /i);
  119. retRE = new RegExp(/Morceaux .cout.s r.cemment/i);
  120. taRE = new RegExp(/Top Artistes/i);
  121. ttRE = new RegExp(/Top Titres/i);
  122. rarRE = new RegExp(/Articles li.s/i);
  123. pliRE = new RegExp(/Plus d.infos/i);
  124. liRE = new RegExp(/Auditeurs/i);
  125. lnRE = new RegExp(/coutent en ce moment/i);
  126. ltRE = new RegExp(/Tendance d..coute/i);
  127. emnRE = new RegExp(/Newsletter par email/i);
  128. simRE = new RegExp(/similaires/i);
  129. vidRE = new RegExp(/Vid.os/i);
  130. } // for German
  131. if (location.href.match(/www.lastfm.de/i)) {
  132. raRE = new RegExp(/Letzte Aktivit.ten/i);
  133. rvRE = new RegExp(/Letzte Besucher/i);
  134. amRE = new RegExp(/.ber mich/i);
  135. frRE = new RegExp(/[^ ]Freunde /i);
  136. lbfrRE = new RegExp(/(Eure gemeinsamen Freunde|Ihr seid verbunden durch)/);
  137. arRE = new RegExp(/Blogeintr.ge/i);
  138. grRE = new RegExp(/Gruppen/i);
  139. neRE = new RegExp(/Nachbarn/i);
  140. libRE = new RegExp(/ Musiksammlung/i);
  141. retRE = new RegExp(/K.rzlich angeh.rte Titel/i);
  142. taRE = new RegExp(/Top-K.nstler/i);
  143. talRE = new RegExp(/Top.Alben/i);
  144. ttRE = new RegExp(/Top-Titel/i);
  145. // rarRE = new RegExp(/Blogeintr.ge/i);
  146. pliRE = new RegExp(/Weitere Informationen/i);
  147. liRE = new RegExp(/Top-H.rer/i);
  148. lnRE = new RegExp(/Aktuelle.H.rer/i);
  149. // ltRE = new RegExp(/H.rtrend/i);
  150. simRE = new RegExp(/.hnliche K.nstler/i);
  151. } // Spanish
  152. if (location.href.match(/www.lastfm.es/i)) {
  153. raRE = new RegExp(/Actividad reciente/i);
  154. rvRE = new RegExp(/Visitas recientes/i);
  155. amRE = new RegExp(/Con.ceme/i);
  156. frRE = new RegExp(/Amigos/i);
  157. arRE = new RegExp(/Blogs/i);
  158. grRE = new RegExp(/Grupos/i);
  159. neRE = new RegExp(/Vecinos/i);
  160. libRE = new RegExp(/Colecci.n de /i);
  161. retRE = new RegExp(/Temas escuchados recientemente/i);
  162. taRE = new RegExp(/Artistas m.s escuchados/i);
  163. talRE = new RegExp(/.lbumes m.s escuchados/i);
  164. ttRE = new RegExp(/Temas m.s escuchados/i);
  165. rarRE = new RegExp(/Blogs relacionados/i);
  166. pliRE = new RegExp(/M.s informaci.n/i);
  167. liRE = new RegExp(/Oyentes/i);
  168. simRE = new RegExp(/Artistas similares/i);
  169. sbRE = new RegExp(/Notas/i);
  170. evRE = new RegExp(/Eventos/i);
  171. vidRE = new RegExp(/V.deos/i);
  172. } // Swedish
  173. if (location.href.match(/www.lastfm.se/i)) {
  174. raRE = new RegExp(/Senaste aktiviteter/i);
  175. rvRE = new RegExp(/Senaste bes.karna/i);
  176. amRE = new RegExp(/Om mig/i);
  177. frRE = new RegExp(/V.nner/i);
  178. arRE = new RegExp(/Bloggar/i);
  179. grRE = new RegExp(/Grupper/i);
  180. neRE = new RegExp(/Grannar/i);
  181. libRE = new RegExp(/ bibliotek/i);
  182. retRE = new RegExp(/Senast spelade l.tar/i);
  183. taRE = new RegExp(/Toppartister/i);
  184. talRE = new RegExp(/Toppalbum/i);
  185. ttRE = new RegExp(/Toppl.tar/i);
  186. rarRE = new RegExp(/Relaterade bloggar/i);
  187. pliRE = new RegExp(/Mer information/i);
  188. liRE = new RegExp(/Lyssnare/i);
  189. simRE = new RegExp(/Liknande artister/i);
  190. sbRE = new RegExp(/Hojtl.da/i);
  191. evRE = new RegExp(/Spelningar/i);
  192. vidRE = new RegExp(/Videor/i);
  193. } // Italian
  194. if (location.href.match(/www.lastfm.it/i)) {
  195. raRE = new RegExp(/Attivit. recenti/i);
  196. rvRE = new RegExp(/Visitatori recenti/i);
  197. amRE = new RegExp(/Descrizione/i);
  198. frRE = new RegExp(/Amici/i);
  199. arRE = new RegExp(/Articoli /i);
  200. grRE = new RegExp(/Gruppi/i);
  201. neRE = new RegExp(/Grannar/i);
  202. libRE = new RegExp(/Libreria di /i);
  203. retRE = new RegExp(/Brani ascoltati di recente/i);
  204. taRE = new RegExp(/Artisti pi. ascoltati/i);
  205. talRE = new RegExp(/Album pi. ascoltati/i);
  206. ttRE = new RegExp(/Brani pi. ascolta/i);
  207. rarRE = new RegExp(/Articoli correlati/i);
  208. pliRE = new RegExp(/Ulteriori informazioni/i);
  209. liRE = new RegExp(/Ascoltatori/i);
  210. simRE = new RegExp(/Artisti simili/i);
  211. sbRE = new RegExp(/Bacheca/i);
  212. evRE = new RegExp(/Eventi/i);
  213. vidRE = new RegExp(/Video/i);
  214. } // Portuguese
  215. if (location.href.match(/www.lastfm.com.br/i)) {
  216. raRE = new RegExp(/Atividade recente/i);
  217. rvRE = new RegExp(/Visitantes recentes/i);
  218. amRE = new RegExp(/Sobre mim/i);
  219. frRE = new RegExp(/Amigos/i);
  220. arRE = new RegExp(/Posts /i);
  221. grRE = new RegExp(/Grupos/i);
  222. neRE = new RegExp(/Vizinhos/i);
  223. libRE = new RegExp(/Biblioteca de /i);
  224. retRE = new RegExp(/.ltimas faixas/i);
  225. taRE = new RegExp(/Principais artistas/i);
  226. talRE = new RegExp(/Principais .lbuns/i);
  227. ttRE = new RegExp(/As faixas mais tocadas/i);
  228. rarRE = new RegExp(/Blogs relacionados/i);
  229. pliRE = new RegExp(/Mais informa..es/i);
  230. liRE = new RegExp(/Ouvintes/i);
  231. simRE = new RegExp(/Parecidos/i);
  232. sbRE = new RegExp(/Caixa de mensagens/i);
  233. evRE = new RegExp(/Eventos/i);
  234. vidRE = new RegExp(/V.deos/i);
  235. }
  236. writeHideSnyde();
  237.  
  238. if (document.getElementById("player")) {
  239. var plyrNode = document.getElementById("player");
  240. var prePlyr = document.createElement("DIV");
  241. prePlyr.innerHTML = "<H2 Class='heading'><span class='h2Wrapper'><A style=\"color: #ff0000;\" HREF=\"javascript:(hydeSnyde('player','P'))\">+/&ndash;</A> / Player</span></H2>";
  242. plyrNode.parentNode.insertBefore(prePlyr,plyrNode);
  243. drudgeWork(plyrNode,"player","P");
  244. }
  245. var activityHdr = xpath("//H2"); // xpath("//H2[contains(@Class, 'heading')]");
  246. for (var i=0; i<activityHdr.snapshotLength; i++) {
  247. if (activityHdr.snapshotItem(i).innerHTML.match(raRE)){
  248. var myNode=activityHdr.snapshotItem(i);
  249. if (myNode.nextSibling.nextSibling.nextSibling.nextSibling.tagName.match(/UL/i)) {
  250. myNode.nextSibling.nextSibling.nextSibling.nextSibling.setAttribute("id","MyActivityBox");
  251. } else {
  252. myNode.nextSibling.nextSibling.setAttribute("id","MyActivityBox");
  253. }
  254. drudgeWork(myNode,"MyActivityBox","R");
  255. }
  256. if (activityHdr.snapshotItem(i).innerHTML.match(rvRE)){
  257. drudgeWork(activityHdr.snapshotItem(i),"MyRVisitorsBox","V");
  258. }
  259. if (activityHdr.snapshotItem(i).innerHTML.match(amRE)){
  260. drudgeWork(activityHdr.snapshotItem(i),"MyMeBox","A");
  261. }
  262. if (activityHdr.snapshotItem(i).innerHTML.match(liRE)){
  263. drudgeWork(activityHdr.snapshotItem(i),"MyHearYa","H");
  264. }
  265. if (activityHdr.snapshotItem(i).innerHTML.match(lnRE)){
  266. drudgeWork(activityHdr.snapshotItem(i),"MyHearNow","h");
  267. }
  268. if (activityHdr.snapshotItem(i).innerHTML.match(ltRE)){
  269. drudgeWork(activityHdr.snapshotItem(i),"MyHearTrnd","d");
  270. }
  271. // if (activityHdr.snapshotItem(i).innerHTML.match(emnRE)){
  272. // drudgeWork(activityHdr.snapshotItem(i),"MyEmailNews","e");
  273. // }
  274. if (activityHdr.snapshotItem(i).innerHTML.match(rarRE)){
  275. drudgeWork(activityHdr.snapshotItem(i),"ArtJournalsBox","Q");
  276. }
  277. if (activityHdr.snapshotItem(i).innerHTML.match(pliRE)){
  278. drudgeWork(activityHdr.snapshotItem(i),"ArtInfoBox","I");
  279. }
  280. if (activityHdr.snapshotItem(i).innerHTML.match(frRE)){
  281. drudgeWork(activityHdr.snapshotItem(i),"MyFriendsBox","F");
  282. }
  283. if (activityHdr.snapshotItem(i).innerHTML.match(lbfrRE)){
  284. drudgeWork(activityHdr.snapshotItem(i),"MyFriendsLab","f");
  285. }
  286. if (activityHdr.snapshotItem(i).innerHTML.match(arRE) && !location.href.match(/\/music\//) ){
  287. drudgeWork(activityHdr.snapshotItem(i),"MyJournalsBox","J");
  288. }
  289. if (activityHdr.snapshotItem(i).innerHTML.match(grRE)){
  290. drudgeWork(activityHdr.snapshotItem(i),"MyGroupsBox","G");
  291. }
  292. if (activityHdr.snapshotItem(i).innerHTML.match(evRE)){
  293. drudgeWork(activityHdr.snapshotItem(i),"MyEventBox","E");
  294. }
  295. if (activityHdr.snapshotItem(i).innerHTML.match(neRE)){
  296. drudgeWork(activityHdr.snapshotItem(i),"MyNeighboursBox","N");
  297. }
  298. if (activityHdr.snapshotItem(i).innerHTML.match(libRE)){
  299. drudgeWork(activityHdr.snapshotItem(i),"MyLibraryBox","L");
  300. }
  301. if (activityHdr.snapshotItem(i).innerHTML.match(sbRE)){
  302. drudgeWork(activityHdr.snapshotItem(i),"MyYelling","Y");
  303. }
  304. if (activityHdr.snapshotItem(i).innerHTML.match(retRE)){
  305. var nodeIWant = activityHdr.snapshotItem(i).parentNode.getElementsByTagName("TABLE");
  306. if (nodeIWant.length > 0) {
  307. nodeIWant[0].setAttribute("id","MyTracksBox");
  308. drudgeWork(activityHdr.snapshotItem(i),"MyTracksBox","T");
  309. }
  310. }
  311. if (activityHdr.snapshotItem(i).innerHTML.match(taRE)){
  312. var nodeIWant = activityHdr.snapshotItem(i).parentNode.getElementsByTagName("DIV");
  313. if (nodeIWant.length > 2) {
  314. var nodeNum = 2; if (location.href.match(/\/place\//)) {nodeNum=1; }
  315. nodeIWant[nodeNum].setAttribute("id","MyTopBands");
  316. drudgeWork(activityHdr.snapshotItem(i),"MyTopBands","B");
  317. }
  318. }
  319. if (activityHdr.snapshotItem(i).innerHTML.match(ttRE)){
  320. var nodeIWant = activityHdr.snapshotItem(i).parentNode.getElementsByTagName("DIV");
  321. if (location.href.match(/\/music\//) || location.href.match(/\/place\//)) {
  322. if (nodeIWant.length > 1) {
  323. nodeIWant[1].setAttribute("id","MyTopSongs");
  324. drudgeWork(activityHdr.snapshotItem(i),"MyTopSongs","S");
  325. }
  326. } else {
  327. if (nodeIWant.length > 2) {
  328. nodeIWant[2].setAttribute("id","MyTopSongs");
  329. drudgeWork(activityHdr.snapshotItem(i),"MyTopSongs","S");
  330. }
  331. }
  332. }
  333. if (activityHdr.snapshotItem(i).innerHTML.match(talRE)){
  334. var nodeIWant = activityHdr.snapshotItem(i).parentNode.getElementsByTagName("DIV");
  335. if (!document.getElementById("MyTopAlbums")) {
  336. drudgeWork(activityHdr.snapshotItem(i),"MyTopAlbums","W");
  337. } else {
  338. if (location.href.match(/\/music\//) || location.href.match(/\/place\//)) {
  339. if (nodeIWant.length > 1) {
  340. nodeIWant[1].setAttribute("id","MyTopAlbums");
  341. drudgeWork(activityHdr.snapshotItem(i),"MyTopAlbums","W");
  342. }
  343. } else {
  344. if (nodeIWant.length > 2) {
  345. nodeIWant[2].setAttribute("id","MyTopAlbums");
  346. drudgeWork(activityHdr.snapshotItem(i),"MyTopAlbums","W");
  347. }
  348. }
  349. }
  350. }
  351. if (activityHdr.snapshotItem(i).innerHTML.match(simRE)){
  352. drudgeWork(activityHdr.snapshotItem(i),"ArtPretend","D");
  353. }
  354. if (activityHdr.snapshotItem(i).innerHTML.match(vidRE)){
  355. drudgeWork(activityHdr.snapshotItem(i),"MyTopVideo","X");
  356. }
  357. }
  358. }) ();
  359. function writeHideSnyde() { if (! document.getElementById('HydeVSJekyll') ) {
  360. // var contextElem = document.getElementById("content");
  361. // var contextElem = document.getElementById("fauxHeaderContainer");
  362. var contextElem = document.getElementById("page");
  363. var theScriptText = "";
  364. theScriptText += "function hydeSnyde(drJekyll,jsLab) { var Jekyll = document.getElementById(drJekyll);";
  365. theScriptText += "var myDte = new Date((new Date()).getTime() + (2*365*24*3600*1000)); ";
  366. theScriptText += " if (document.cookie.match(/HydeVSJekyll=/)) {";
  367. theScriptText += " var oldCookie = document.cookie.match(/HydeVSJekyll=([^;]*)[;$]/)[1];";
  368. theScriptText += " } else {var oldCookie = ''; }";
  369. theScriptText += "if (Jekyll.getAttribute('style') == null) ";
  370. theScriptText += "{Jekyll.setAttribute('style','display: none; visibility: hidden;'); ";
  371. theScriptText += " oldCookie += jsLab;";
  372. theScriptText += "} else { Jekyll.removeAttribute('style'); var jsLabRE = new RegExp(jsLab,'g'); oldCookie = oldCookie.replace(jsLabRE,'');} ";
  373. theScriptText += " var myCke = 'HydeVSJekyll='+oldCookie+'; expires='+myDte.toGMTString()+';';";
  374. theScriptText += " document.cookie = myCke;";
  375. theScriptText += "};";
  376. var theScript = document.createElement("script"); theScript.setAttribute('language','JavaScript'); theScript.setAttribute('id','HydeVSJekyll');
  377. theScript.innerHTML = theScriptText;
  378. contextElem.insertBefore(theScript,contextElem.firstChild);
  379. }}