FetLife Common Fetishes

Display shared fetishes in bold

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey, το Greasemonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Userscripts για να εγκαταστήσετε αυτόν τον κώδικα.

You will need to install an extension such as Tampermonkey to install this script.

Θα χρειαστεί να εγκαταστήσετε μια επέκταση διαχείρισης κώδικα χρήστη για να εγκαταστήσετε αυτόν τον κώδικα.

(Έχω ήδη έναν διαχειριστή κώδικα χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Έχω ήδη έναν διαχειριστή στυλ χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

// ==UserScript==
// @name           FetLife Common Fetishes
// @namespace      kirr.fetlife
// @description    Display shared fetishes in bold
// @include        https://fetlife.com/users/*
// @exclude        https://fetlife.com/users/*/*
// @author         Kirr (https://fetlife.com/kirr)
// @url            https://fetlife.com/users/27238/posts/500942
// @version 0.0.1.20141106222820
// ==/UserScript==

// Workaround for Chromium.
if (!this.GM_getValue || 
    (this.GM_getValue.toString && 
     this.GM_getValue.toString().indexOf("not supported")>-1))
{
    this.GM_getValue=function (key,def) {
        return localStorage[key] || def;
    };
    this.GM_setValue=function (key,value) {
        return localStorage[key]=value;
    };
}

/* All links in the page. */
var hrefs=document.getElementsByTagName("a");

/* Check if we're viewing our own profile. We do this by finding the
 * first link to a user account (which will be the link to our own
 * account, in the heading) and compare that to the URL. 
 */
function is_this_my_profile()
{
  for(var i=0;i<hrefs.length;i++)
  {
    if(hrefs[i].href.match("/users/[0-9]+$"))
    {
      // The "match" here is to deal with situations like a # at the
      // end of the URL.
      if(hrefs[i].href==location.href.match(".*/users/[0-9]+")[0])
      {
        return 1;
      } else {
        return 0;
      }
    }
  }
  return 0;
}

/* If we're on our own profile page, we'll cache our fetish list. */
function save_my_fetishes()
{
  var fetishstr="";
  for(var i=0;i<hrefs.length;i++)
  {
    // Is this a link to a fetish page?
    if(hrefs[i].href.match("/fetishes/[0-9]+"))
    {
      // Yup. Add it to the string.
      var fetishnum=hrefs[i].href.match("[0-9]+");
      fetishstr+=":"+fetishnum;
    }
  }
  // Save a colon-separated list of the fetishes we're in.
  GM_setValue("fetish_cache",fetishstr);
}

/* Return a hashtable of fetishes. 1 in the table means the fetish is
 * present; undefined means it's not.
 */
function load_my_fetishes()
{
  var fetishstr=GM_getValue("fetish_cache","");
  // An array of the fetishes we're in. Fetish numbers here are
  // values, not keys.
  var fetisharray=fetishstr.split(":");
  // For lookup up fetishes, though, we want fetishes as *keys*, which
  // we do here.
  var fetishhash=[];

  // 1 here is not a bug; the first item is empty.
  for(var i=1;i<fetisharray.length;i++)
  {
    fetishhash[fetisharray[i]]=1;
  }

  return fetishhash;
}

/* Given a hashtable of fetishes, make the appropriate ones bold. */
function boldify(fetishhash)
{
  for(var i=0;i<hrefs.length;i++)
  {
    if(hrefs[i].href.match("/fetishes/[0-9]*"))
    {
      var fetishnum=hrefs[i].href.match("[0-9]+");
      if(fetishhash[fetishnum])
        hrefs[i].innerHTML="<b><font color='red'>"+hrefs[i].innerHTML+"</font></b>";
    }
  }
}


if(is_this_my_profile())
{
  save_my_fetishes();
} else {
  boldify(load_my_fetishes());
}