Skip to content

Instantly share code, notes, and snippets.

View RichardDillman's full-sized avatar

Richard Dillman RichardDillman

View GitHub Profile
@RichardDillman
RichardDillman / colors.js
Created December 30, 2017 09:32
Find all colors used on the page and out put to the console.
(function() {
var h = {};
var e = ["background-color", "color", "border-top-color", "border-right-color", "border-bottom-color", "border-left-color"];
var g = {
"rgb(0, 0, 0)": 1,
"rgba(0, 0, 0, 0)": 1,
"rgb(255, 255, 255)": 1
};
[].forEach.call(document.querySelectorAll("*"), function(i) {
var j = {};
@RichardDillman
RichardDillman / globals.js
Created December 30, 2017 09:31
Find all globals not native to the window object.
(function f() {
var frm = document.createElement("iframe");
frm.style.display = "none";
document.body.appendChild(frm);
var a = Object.getOwnPropertyNames(frm.contentWindow);
var b = Object.getOwnPropertyNames(window);
var tab = {};
b.filter(function(c) {
return a.indexOf(c) === -1;
}).map(function(i) {
@RichardDillman
RichardDillman / getAdData.js
Created December 30, 2017 09:31
This code will display page level targeting and slot level data including sizes, targeting, outOfPage, elementId, advertiserId, campaignId, creativeId, isBackfill, labelIds, lineItemId, outOfPage, sourceAgnosticCreativeId, sourceAgnosticLineItemId, and a URL to this creative at DFP
/**
* Gathers the page targeting data.
*
* @private
* @param {Object} page - The internal object to append data to.
* @returns {undefined}
*/
function getPageTargeting(page) {
window.googletag.pubads().getTargetingKeys().forEach(function(keys) {
page.pageTargeting[keys] = window.googletag.pubads().getTargeting(keys);
@RichardDillman
RichardDillman / isFriendlyIframe.js
Created December 30, 2017 09:30
Check if we have access to the iframe body.
/**
* Determines if the passed iframe is a friendly iframe.
*
* @param {HTMLElement} iframe The iframe under test.
* @return {boolean} True if friendly iframe, False otherwise.
*/
function isFriendlyIframe(iframe) {
var html = null;
try {
// deal with older browsers
@RichardDillman
RichardDillman / isHidden.js
Last active March 6, 2018 04:30
If the element were in the view-port, could we see it?
/**
* is-visible
* @description Determine if the element is hidden from view:
* * Via css with opacity, display, or visibility.
* * Removed from the DOM, or not yet appended to the DOM.
* * Within the overflow of an ancestor.
* * Within a hidden ancestor.
*/
/**
@RichardDillman
RichardDillman / throttle.js
Created December 30, 2017 09:29
Throttle function
/**
* Throttle functions.
*
* @param {Function} fn - The function to be throttled.
* @param {number} delay - The delay time in milliseconds.
* @param {Object|HTMLElement} scope - What this should be inside the function.
* @return {Function} - The throttled function wrapped with a new function.
*/
function throttle(fn, delay, scope) {
delay = delay || 250;