Evex Banner Contest Viewer

Previews banners for the reddit.com/r/EVEX banner contest

  1. // ==UserScript==
  2. // @name Evex Banner Contest Viewer
  3. // @namespace faubiguy
  4. // @version 0.1
  5. // @description Previews banners for the reddit.com/r/EVEX banner contest
  6. // @author faubiguy
  7. // @match https://www.reddit.com/r/EVEX/comments/3uztta/*
  8. // @grant none
  9. // ==/UserScript==
  10. /* jshint -W097 */
  11. 'use strict';
  12.  
  13. if (document.body.classList.contains('comment-permalink-page')) {
  14. console.log('Switching banner image');
  15. var commentbody = document.getElementsByClassName('comment')[0].getElementsByClassName('usertext-body')[0];
  16. var imagelinks = Array.prototype.slice.call(commentbody.getElementsByTagName('a')).filter(function(url){return /\.(jpg|jpeg|png|gif)($|\?)/.exec(url.href);});
  17. console.log(Array.prototype.slice.call(commentbody.getElementsByTagName('a')).map(function(url){return url.href}));
  18. if (imagelinks.length === 0) {
  19. console.log('No images found');
  20. return;
  21. }
  22. console.log('Found an image to use: ' + imagelinks[0].href);
  23. var newstyle = document.createElement('style');
  24. newstyle.innerHTML = '#header{background-image:url("'+ imagelinks[0].href +'")!important;}';
  25. document.head.appendChild(newstyle);
  26. console.log('Appended style');
  27. }