Skip to content

Instantly share code, notes, and snippets.

View mcseptian's full-sized avatar
🏠
Working from home

Septian Adi mcseptian

🏠
Working from home
View GitHub Profile
@cssence
cssence / listAllUsedClassNames.js
Created July 14, 2015 14:37
List all used CSS classes
(function listAllUsedClassNames () {
var classNames = {};
Array.prototype.forEach.call(document.querySelectorAll("*"), function (element) {
if (typeof element.className === "string") {
element.className.split(" ").forEach(function (className) {
if (className) {
classNames[className] = true;
}
});
};
@danielpataki
danielpataki / compatibility.js
Last active October 17, 2020 00:06
jQuery in WordPress
/* Regular jQuery */
$('.hideable').on('click', function() {
$(this).hide();
})
/* Compatibility Mode */
jQuery('.hideable').on('click', function() {
jQuery(this).hide();
})
@thegitfather
thegitfather / vanilla-js-cheatsheet.md
Last active April 28, 2025 16:22
Vanilla JavaScript Quick Reference / Cheatsheet
@netsi1964
netsi1964 / ChromeGetUsedClassesAsCSS.js
Created December 1, 2016 10:56
Chrome developer toolbar util: Get CSS containing used CSS classes used below a specified selector
var allClasses = {}, css = '';
var startFrom = prompt('Where should I start?', '#application');
Array.prototype.forEach.call(document.querySelectorAll(startFrom+' *[class]'), function(element) {
Array.prototype.forEach.call(element.classList, function(className) {
if (!allClasses[className]) {
allClasses[className] = 0;
}
allClasses[className]++;
})
});
@joelcardinal
joelcardinal / getCssData.js
Last active May 23, 2019 09:55
Lists pages stylesheet/inline CSS. Also reports CSS selectors used on page from stylesheet/inline and inline JS.
/*
TODO: add check for used Font Family, refactor
*/
(function getStyleSheetsCssData(){
var styleSheets = document.styleSheets,
data = {
cssData : {
allUsedSelectorText : []
},
jsData : []
@guilhermejcgois
guilhermejcgois / getStyle.ts
Last active July 20, 2023 11:38
Get computed styles (in typescript)
// Gist adapted from: https://gist.github.com/cms/369133
export getStyle(el: Element, styleProp: string): string {
let value;
const defaultView = el.ownerDocument.defaultView;
// W3C standard way:
if (defaultView && defaultView.getComputedStyle) {
// sanitize property name to css notation (hypen separated words eg. font-Size)
styleProp = styleProp.replace(/([A-Z])/g, '-$1').toLowerCase();
return defaultView.getComputedStyle(el, null).getPropertyValue(styleProp);
} else if (el['currentStyle']) { // IE
@anthrotype
anthrotype / svg2glif.py
Created September 8, 2017 13:02
svg2glif: convert SVG paths to UFO glyphs
#!/usr/bin/env python
""" Convert SVG paths to UFO glyphs.
"""
# Author: Cosimo Lupo
# Email: [email protected]
# License: Apache Software License 2.0
from __future__ import print_function, absolute_import
__requires__ = ["svg.path", "ufoLib", "FontTools"]
@victor-homyakov
victor-homyakov / detect-unused-css-selectors.js
Last active May 1, 2025 17:28
Detect unused CSS selectors. Show possible CSS duplicates. Monitor realtime CSS usage.
/* eslint-disable no-var,no-console */
// detect unused CSS selectors
(function() {
var parsedRules = parseCssRules();
console.log('Parsed CSS rules:', parsedRules);
detectDuplicateSelectors(parsedRules);
var selectorsToTrack = getSelectorsToTrack(parsedRules);
window.selectorStats = { unused: [], added: [], removed: [] };
console.log('Tracking style usage (inspect window.selectorStats for details)...');
const copyToClipboard = str => {
const el = document.createElement('textarea'); // Create a <textarea> element
el.value = str; // Set its value to the string that you want copied
el.setAttribute('readonly', ''); // Make it readonly to be tamper-proof
el.style.position = 'absolute';
el.style.left = '-9999px'; // Move outside the screen to make it invisible
document.body.appendChild(el); // Append the <textarea> element to the HTML document
const selected =
document.getSelection().rangeCount > 0 // Check if there is any content selected previously
? document.getSelection().getRangeAt(0) // Store selection if found
@renoirb
renoirb / extractcss.js
Last active January 20, 2020 10:19
Extract CSS for a given element
/**
* Based on work from krasimirtsonev
*
* http://krasimirtsonev.com/blog/article/csssteal-chrome-extension-that-extracts-css
*/
// helper function for transforming
// node.children to Array
function toArray (obj, ignoreFalsy) {
var arr = [], i;