Better FetLife

Enhances the functionality of various features of FetLife.com. Best used in conjunction with other browser add-ons, such as those that reveal Microformats.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey, Greasemonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्क्रिप्ट व्यवस्थापक एक्स्टेंशन इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्क्रिप्ट व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्टाईल व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

/**
 *
 * This is a Greasemonkey script and must be run using a Greasemonkey-compatible browser.
 *
 * @author maymay <[email protected]>
 * @author Marnen Laibow-Koser <[email protected]>
 */
// ==UserScript==
// @name           Better FetLife
// @version        0.2
// @namespace      com.maybemaimed.fetlife.better
// @description    Enhances the functionality of various features of FetLife.com. Best used in conjunction with other browser add-ons, such as those that reveal Microformats.
// @include        /^https?://fetlife\.com/(user|event)s/\d+/
// @require        https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js
// @grant          GM_log
// ==/UserScript==

var FL_BETTER = {};
FL_BETTER.CONFIG = {
    'debug': false, // switch to true to debug.
};

// Utility debugging function.
FL_BETTER.log = function (msg) {
    if (!FL_BETTER.CONFIG.debug) { return; }
    GM_log('BETTER FETLIFE: ' + msg);
};

// Initializations.
FL_BETTER.init = function () {
    FL_BETTER.main();
};
window.addEventListener('DOMContentLoaded', FL_BETTER.init);

// This is the main() function, executed on page load.
// TODO: Mark up events on user pages and users on event pages.
FL_BETTER.main = function () {
    // Determine what type of page and what its ID number is.
    var m = window.location.pathname.match(/^\/(user|event)s\/(\d+)$/);
    FL_BETTER.log('Loaded page for ' + m[1] + ' number ' + m[2] + '.');
    switch (m[1]) {
        // If on a user profile page,
        case 'user':
            FL_BETTER.processUser();
        break;

        // If on an event page,
        case 'event':
            FL_BETTER.processEvent();
        break;
    }
};

FL_BETTER.processEvent = function () {
    var parseDateTime = function (metaDateTimeElement) {
        return metaDateTimeElement.attr('content').replace(/Z$/, '');
    };

    var dateTimeMarkup = function (dateTimeString) {
        return $('<abbr class="value"></abbr>').attr('title', dateTimeString);
    };

    var addTimeMarkup = function (startOrEnd) {
        var timeElement = $('[itemprop=' + startOrEnd + 'Date]');
        var dateTimeString = timeElement[0] ? parseDateTime(timeElement) : null;
        var container = $('<span></span>').addClass('dt' + startOrEnd);
        container.append(dateTimeMarkup(dateTimeString));
        timeElement.after(container);
    };

    $("[itemtype='http://schema.org/Event']").addClass('vevent');
    $('h1[itemprop=name]').addClass('summary');
    $('[itemprop=description]').addClass('description');

    // TODO: Parse venues out of location data and mark them up using hCards
    //       See: http://microformats.org/wiki/hcalendar-brainstorming#hCard_locations
    $($('[itemprop=location]').parents().children('span')[1]).addClass('location');

    addTimeMarkup('start');
    addTimeMarkup('end');

    // Write out URL.
    $('.vevent .description').append('<a style="display: none;" class="url" href="' + window.location.href + '">Make FetLife Better.</a>');
};

FL_BETTER.processUser = function () {
    // Add hCard classes for markup that's done right.
    $('#profile').addClass('vcard');
    $('#profile .pan').addClass('photo');
    $('h2.bottom + p').addClass('adr');
    $($('h2.bottom + p a[href^="/cities"]')).addClass('locality');
    $($('h2.bottom + p a[href^="/administrative_areas"]')).addClass('region');
    $($('h2.bottom + p a[href^="/countries"]')).addClass('country-name');

    // Isolate name and add microformat markup.
    $($('h2.bottom').contents()[0]).wrap('<span class="fn" />');

    // Isolate "About me" content and add microformat markup.
    $($('h3.bottom::first-child').nextUntil('h3.bottom')).wrapAll('<div class="note" />')

    // Write out URL.
    $('#profile').append('<a style="display: none;" class="url" href="' + window.location.href + '">Make FetLife Better.</a>');

};