CSS rule finder

function allowing to get the CSS rules applied to an element

As of 15. 01. 2020. See the latest version.

This script should not be not be installed directly. It is a library for other scripts to include with the meta directive // @require https://update.greasyfork.org/scripts/394970/765702/CSS%20rule%20finder.js

// ==UserScript==
// @name         CSS rule finder
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  function allowing to get the CSS rules applied to an element
// @author       You
// @match        http://*/*
// @grant        none
// ==/UserScript==

function css(el) {
    var sheets = document.styleSheets, ret = [];
    el.matches = el.matches || el.webkitMatchesSelector || el.mozMatchesSelector || el.msMatchesSelector || el.oMatchesSelector;
    for (var i in sheets) {
        var rules = sheets[i].rules || sheets[i].cssRules;
        for (var r in rules) {
            if (el.matches(rules[r].selectorText)) {
                ret.push(rules[r].cssText);
            }
        }
    }
    return ret;
}