Skip to content

Instantly share code, notes, and snippets.

import { LitElement, html, property, customElement } from 'lit-element';
@customElement('simple-greeting')
export class SimpleGreeting extends LitElement {
@property() name = 'World';
render() {
return html`<p>Hello, ${this.name}!</p>`;
}
}
@cssimsek
cssimsek / flatten_w3c_datalayer.js
Last active June 23, 2019 01:30
Flatten W3C Data Layer to flat Tealium utag
(function (w) {
let w3c_DL_NS = 'YOUR_W3C_DL_NS';
if (w3c_DL_NS in w && 'utag_data' in w) {
w3c_DL_NS = w[w3c_DL_NS];
flatten(w3c_DL_NS);
}
function flatten(object, keyTree) {
keyTree = keyTree || 'w3c';
if (object instanceof Object) {
@cssimsek
cssimsek / lytics_dfp_integration.js
Created June 18, 2018 10:34
Lytics Audiences to DFP Integration JS - from https://goo.gl/CyUnFf
!function (l, a) {
a.liosetup = a.liosetup || {}, a.liosetup.callback = a.liosetup.callback || [], a.liosetup.addCallback = function (l) {
if ("function" == typeof a.liosetup.callback) {
var o = [];
o.push(a.liosetup.callback), a.liosetup.callback = o
}
a.lio && a.lio.loaded ? l(a.lio.data) : a.liosetup.callback.push(l)
}
}(document, window);
!function (o, g) {
/*
* Get Human Readable Location
* Uses https://api.ipify.org to get ip
* Uses https://freegeoip.net to get location info
*/
window.getPublicIP = function(json) {
makeScript("https://freegeoip.net/json/"+json.ip+"?",{callback:"getRealLocation"});
}
window.getRealLocation = function(json){
@cssimsek
cssimsek / addWordsTimeout
Last active August 29, 2015 14:03
Add text with steps following a particular element
var parElement = document.getElementById("lga"); //get parent element
var containerDiv = document.createElement("div");// create new container div
insertAfter(containerDiv, parElement); //insertAfter function defined below
var myWords = ["Hi", "my", "name", "is", "Paradoxus"]; //array of words to be added
var i = 0;
function addMyWords(i){
if(i < myWords.length){
parElement.nextSibling.textContent += myWords[i] + "\n";
i++;
var timeoutID = window.setTimeout(function(){addMyWords(i)}, 2000);
@cssimsek
cssimsek / array emptier
Created May 16, 2014 10:11
Empty an array by popping the elements
var myArray = [0, 1, 2, 3, 4, 5];
console.log(myArray);
var originalLength = myArray.length;
for(var i = originalLength; i > 0; i--) {
myArray.pop();
console.log(myArray);
}
@cssimsek
cssimsek / iframe remover
Last active August 29, 2015 13:56
Function which removes all iframes present on a page
function iframeKilla() {
var iframeEls = document.getElementsByTagName("iframe");
var iframeLength = iframeEls.length;
console.log(iframeEls.length);
while(iframeLength > 0) {
iframeEls[iframeLength - iframeLength].remove();
console.log(iframeEls.length);
}
};
iframeKilla();
@cssimsek
cssimsek / Checklist bulk manipulator
Last active January 3, 2016 08:19
Select or deselect all checklist items present on a page (for example history items on chrome://history-frame). When invoking checkAll, the argument checkVal should be set to "true" to check all, and "false" to deselect (uncheck).
function checkAll(checkVal){
var removeMult = document.getElementById("remove-selected");
removeMult.removeAttribute("disabled");
var c = [];
c = document.getElementsByTagName('input');
console.log(c);
for (var i = 0; i < c.length; i++)
{
if (c[i].type == 'checkbox')
{
@cssimsek
cssimsek / ga.js and analytics.js presence checker
Created January 9, 2014 13:51
Very basic JS script to check if ga.js or analytics.js scripts (standard implementations) are present on a page
(function(){
var myScripts = document.getElementsByTagName("script");
var result = [];
for(var i = 0; i < myScripts.length; i += 1){
if(myScripts[i].src.substr(-12, 12) === "analytics.js"){
result.push(myScripts[i].baseURI + " has analytics.js installed");
}
else if(myScripts[i].src.substr(-5, 5) === "ga.js"){
result.push(myScripts[i].baseURI + " has ga.js installed");
}