Evex Banner Contest Viewer

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

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Evex Banner Contest Viewer
// @namespace    faubiguy
// @version      0.1
// @description  Previews banners for the reddit.com/r/EVEX banner contest
// @author       faubiguy
// @match        https://www.reddit.com/r/EVEX/comments/3uztta/*
// @grant        none
// ==/UserScript==
/* jshint -W097 */
'use strict';

if (document.body.classList.contains('comment-permalink-page')) {
    console.log('Switching banner image');
    var commentbody = document.getElementsByClassName('comment')[0].getElementsByClassName('usertext-body')[0];
    var imagelinks = Array.prototype.slice.call(commentbody.getElementsByTagName('a')).filter(function(url){return /\.(jpg|jpeg|png|gif)($|\?)/.exec(url.href);});
    console.log(Array.prototype.slice.call(commentbody.getElementsByTagName('a')).map(function(url){return url.href}));
    if (imagelinks.length === 0) {
        console.log('No images found');
        return;
    }
    console.log('Found an image to use: ' + imagelinks[0].href);
    var newstyle = document.createElement('style');
    newstyle.innerHTML = '#header{background-image:url("'+ imagelinks[0].href +'")!important;}';
    document.head.appendChild(newstyle);
    console.log('Appended style');
}