Skip to content

Instantly share code, notes, and snippets.

View BR0kEN-'s full-sized avatar
⌨️
Coding... A lot.

Sergii Bondarenko BR0kEN-

⌨️
Coding... A lot.
View GitHub Profile
@BR0kEN-
BR0kEN- / js_filename.js
Created January 25, 2014 17:53
PHP __FILE__ magic constant in JavaScript
/**
* __defineGetter__ - IE9+
* new Error - IE10+
*/
window.__defineGetter__('__FILE__', function() {
return (new Error).stack.split('/').slice(-1).join().split('.')[0];
});
console.log(__FILE__); // js_filename
if (!document.querySelectorAll) {
document.querySelectorAll = function (selectors) {
var style = document.createElement('style'), elements = [], element;
document.documentElement.firstChild.appendChild(style);
document._qsa = [];
style.styleSheet.cssText = selectors + '{x-qsa:expression(document._qsa && document._qsa.push(this))}';
window.scrollBy(0, 0);
style.parentNode.removeChild(style);