Last active
July 20, 2018 19:37
-
-
Save revenkroz/fcca22f643523ebbd7160f6ba8611076 to your computer and use it in GitHub Desktop.
List of EW Gallery Images
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name List of EW Gallery Images | |
// @namespace ew | |
// @author Oleg Koval | |
// @match http://ew.com/news/*/* | |
// @version 1.1 | |
// @grant none | |
// ==/UserScript== | |
window.galleryListToggle = false; | |
let galleryImages = document.querySelectorAll('.gallery-content .media-img'); | |
let links = []; | |
let htmlLinks = '<ol>'; | |
for (let i = 0; i < galleryImages.length; i++) { | |
let image = galleryImages[i].getElementsByTagName('img')[0]; | |
const attr = image.getAttribute('data-src') ? 'data-src' : 'src'; | |
links.push(image.getAttribute(attr).replace(/(\?w=\d+)/g, '')); | |
htmlLinks += '<li><a href="' + links[i] +'">'+ links[i] +'</a></li>'; | |
} | |
htmlLinks += '</ol>'; | |
if (links.length > 0) { | |
let title = document.querySelector('.headline'); | |
let titleText = title.innerHTML; | |
title.innerHTML = titleText + ' ' + '<b id="epscape-d-img" style="color: #487FAE; cursor: pointer;">+</b>'; | |
let dImg = document.getElementById('epscape-d-img'); | |
dImg.addEventListener('click', function() { | |
if (window.galleryListToggle) { | |
let galleryList = document.querySelector('.epscape-gallery-list'); | |
galleryList.remove(); | |
dImg.innerHTML = '+'; | |
window.galleryListToggle = false; | |
} else { | |
let header = document.querySelector('.article-header'); | |
let div = document.createElement('div'); | |
div.className = 'epscape-gallery-list'; | |
div.innerHTML = htmlLinks; | |
header.parentNode.insertBefore(div, header.nextSibling); | |
dImg.innerHTML = '-'; | |
window.galleryListToggle = true; | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment