FetLife Common Fetishes

Display shared fetishes in bold

このスクリプトの質問や評価の投稿はこちら通報はこちらへお寄せください。
  1. // ==UserScript==
  2. // @name FetLife Common Fetishes
  3. // @namespace kirr.fetlife
  4. // @description Display shared fetishes in bold
  5. // @include https://fetlife.com/users/*
  6. // @exclude https://fetlife.com/users/*/*
  7. // @author Kirr (https://fetlife.com/kirr)
  8. // @url https://fetlife.com/users/27238/posts/500942
  9. // @version 0.0.1.20141106222820
  10. // ==/UserScript==
  11.  
  12. // Workaround for Chromium.
  13. if (!this.GM_getValue ||
  14. (this.GM_getValue.toString &&
  15. this.GM_getValue.toString().indexOf("not supported")>-1))
  16. {
  17. this.GM_getValue=function (key,def) {
  18. return localStorage[key] || def;
  19. };
  20. this.GM_setValue=function (key,value) {
  21. return localStorage[key]=value;
  22. };
  23. }
  24.  
  25. /* All links in the page. */
  26. var hrefs=document.getElementsByTagName("a");
  27.  
  28. /* Check if we're viewing our own profile. We do this by finding the
  29. * first link to a user account (which will be the link to our own
  30. * account, in the heading) and compare that to the URL.
  31. */
  32. function is_this_my_profile()
  33. {
  34. for(var i=0;i<hrefs.length;i++)
  35. {
  36. if(hrefs[i].href.match("/users/[0-9]+$"))
  37. {
  38. // The "match" here is to deal with situations like a # at the
  39. // end of the URL.
  40. if(hrefs[i].href==location.href.match(".*/users/[0-9]+")[0])
  41. {
  42. return 1;
  43. } else {
  44. return 0;
  45. }
  46. }
  47. }
  48. return 0;
  49. }
  50.  
  51. /* If we're on our own profile page, we'll cache our fetish list. */
  52. function save_my_fetishes()
  53. {
  54. var fetishstr="";
  55. for(var i=0;i<hrefs.length;i++)
  56. {
  57. // Is this a link to a fetish page?
  58. if(hrefs[i].href.match("/fetishes/[0-9]+"))
  59. {
  60. // Yup. Add it to the string.
  61. var fetishnum=hrefs[i].href.match("[0-9]+");
  62. fetishstr+=":"+fetishnum;
  63. }
  64. }
  65. // Save a colon-separated list of the fetishes we're in.
  66. GM_setValue("fetish_cache",fetishstr);
  67. }
  68.  
  69. /* Return a hashtable of fetishes. 1 in the table means the fetish is
  70. * present; undefined means it's not.
  71. */
  72. function load_my_fetishes()
  73. {
  74. var fetishstr=GM_getValue("fetish_cache","");
  75. // An array of the fetishes we're in. Fetish numbers here are
  76. // values, not keys.
  77. var fetisharray=fetishstr.split(":");
  78. // For lookup up fetishes, though, we want fetishes as *keys*, which
  79. // we do here.
  80. var fetishhash=[];
  81.  
  82. // 1 here is not a bug; the first item is empty.
  83. for(var i=1;i<fetisharray.length;i++)
  84. {
  85. fetishhash[fetisharray[i]]=1;
  86. }
  87.  
  88. return fetishhash;
  89. }
  90.  
  91. /* Given a hashtable of fetishes, make the appropriate ones bold. */
  92. function boldify(fetishhash)
  93. {
  94. for(var i=0;i<hrefs.length;i++)
  95. {
  96. if(hrefs[i].href.match("/fetishes/[0-9]*"))
  97. {
  98. var fetishnum=hrefs[i].href.match("[0-9]+");
  99. if(fetishhash[fetishnum])
  100. hrefs[i].innerHTML="<b><font color='red'>"+hrefs[i].innerHTML+"</font></b>";
  101. }
  102. }
  103. }
  104.  
  105.  
  106. if(is_this_my_profile())
  107. {
  108. save_my_fetishes();
  109. } else {
  110. boldify(load_my_fetishes());
  111. }