<commit_before>// ==UserScript==
// @include http://*.reddit.com/*
// @include https://*.reddit.com/*
// ==/UserScript==

/*
 * THIS FILE IS NOT A USERSCRIPT. DO NOT ATTEMPT TO INSTALL IT AS SUCH.
 *
 * The above header is used by Opera.
 */

/*******************************************************************************
**
** Copyright (C) 2012 Typhos
**
** This Source Code Form is subject to the terms of the Mozilla Public
** License, v. 2.0. If a copy of the MPL was not distributed with this
** file, You can obtain one at http://mozilla.org/MPL/2.0/.
**
*******************************************************************************/

"use strict";

// Embed JS files, for Opera
/*$(EMOTE_MAP)*/
/*$(SR_DATA)*/
/*$(SCRIPT_COMMON)*/

// Checks whether the given element has a parent with the given ID. The element
// itself does not count.
function hasParentWithId(element, id) {
    if(element.parentNode !== null) {
        if(element.parentNode.id == id) {
            return true;
        } else {
            return hasParentWithId(element.parentNode, id);
        }
    }
    return false;
}

// Same, but for CSS classes
function hasParentWithClass(element, className) {
    if(element.parentNode !== null && element.parentNode.className !== undefined) {
        if(element.parentNode.className.indexOf(className) > -1) {
            return true;
        } else {
            return hasParentWithClass(element.parentNode, className);
        }
    }
    return false;
}

// Converts an emote name (or similar) to the associated CSS class.
//
// Keep this in sync with the Python code.
function sanitize(s) {
    return s.toLowerCase().replace("!", "_excl_").replace(":", "_colon_");
}

// Emote processing: takes prefs, a pre-processed array of enabled subreddits,
// and a list of elements.
function process(prefs, sr_array, elements) {
    for(var i = 0; i < elements.length; i++) {
        var element = elements[i];
        // There is an important distinction between element.href and
        // element.getAttribute("href")- the former is mangled by the
        // browser to be a complete URL, which we don't want.
        var href = element.getAttribute("href");
        if(href && href[0] == '/') {
            // Don't normalize case for emote lookup
            var parts = href.split("-");
            var emote_name = parts[0];

            if(emote_map[emote_name]) {
                var emote_info = emote_map[emote_name];<commit_msg>Fixed alt-text triggering on random elements<commit_after>// ==UserScript==
// @include http://*.reddit.com/*
// @include https://*.reddit.com/*
// ==/UserScript==

/*
 * THIS FILE IS NOT A USERSCRIPT. DO NOT ATTEMPT TO INSTALL IT AS SUCH.
 *
 * The above header is used by Opera.
 */

/*******************************************************************************
**
** Copyright (C) 2012 Typhos
**
** This Source Code Form is subject to the terms of the Mozilla Public
** License, v. 2.0. If a copy of the MPL was not distributed with this
** file, You can obtain one at http://mozilla.org/MPL/2.0/.
**
*******************************************************************************/

"use strict";

// Embed JS files, for Opera
/*$(EMOTE_MAP)*/
/*$(SR_DATA)*/
/*$(SCRIPT_COMMON)*/

// Checks whether the given element has a parent with the given ID. The element
// itself does not count.
function hasParentWithId(element, id) {
    if(element.parentNode !== null) {
        if(element.parentNode.id == id) {
            return true;
        } else {
            return hasParentWithId(element.parentNode, id);
        }
    }
    return false;
}

// Same, but for CSS classes
function hasParentWithClass(element, className) {
    if(element.parentNode !== null && element.parentNode.className !== undefined) {
        if((" " + element.parentNode.className + " ").indexOf(" " + className + " ") > -1) {
            return true;
        } else {
            return hasParentWithClass(element.parentNode, className);
        }
    }
    return false;
}

// Converts an emote name (or similar) to the associated CSS class.
//
// Keep this in sync with the Python code.
function sanitize(s) {
    return s.toLowerCase().replace("!", "_excl_").replace(":", "_colon_");
}

// Emote processing: takes prefs, a pre-processed array of enabled subreddits,
// and a list of elements.
function process(prefs, sr_array, elements) {
    for(var i = 0; i < elements.length; i++) {
        var element = elements[i];
        // There is an important distinction between element.href and
        // element.getAttribute("href")- the former is mangled by the
        // browser to be a complete URL, which we don't want.
        var href = element.getAttribute("href");
        if(href && href[0] == '/') {
            // Don't normalize case for emote lookup
            var parts = href.split("-");
            var emote_name = parts[0];

            if(emote_map[emote_name]) {
                var emote_info = emote_map[emote_name];
{'fraction_non_alphanumeric': 0.19021848065744637, 'fraction_numerical': 0.004810583283223091, 'mean_word_length': 2.788914198936978, 'pattern_counts': {'":': 2, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4589939', 'n_tokens_mistral': 1431, 'n_tokens_neox': 1401, 'n_words': 467}