Greasy Fork

ZSMTurker's MTG Forum Image Video Spoilerizer (with labels mod)

Spoilerize all images and videos in posts (except TO).

当前为 2014-11-02 提交的版本,查看 最新版本

// ==UserScript==
// @name        ZSMTurker's MTG Forum Image Video Spoilerizer (with labels mod)
// @author      ZSMTurker
// @namespace   mturkgrind
// @namespace   https://greasyfork.org/users/2291
// @description Spoilerize all images and videos in posts (except TO).
// @require     http://code.jquery.com/jquery-latest.min.js
// @match       http://www.mturkgrind.com/*
// @match       https://www.mturkgrind.com/*
// @match       http://www.mturkforum.com/*
// @match       https://www.mturkforum.com/*
// @match       http://mturkforum.com/*
// @match       https://mturkforum.com/*
// @version     0.1c
// ==/UserScript==

// modified by clickhappier to change generic 'Spoiler' designations to specify 'Image Spoiler' or 'Video Spoiler', and added mturkforum urls

$( document ).ready( function() {
    var postDivs = $(document).find('div[id*="post_message"]');
    var imageArray =  $(postDivs).find('img:not([title])').not( 'img[src*="turkopticon"]' ).not( 'img[src*="data.istrack.in"]' );
    var videoArray = $(postDivs).find('iframe');
    
    for (var i=0; i<imageArray.length; i++){
        imageArray.eq(i).before('<div style="margin: 5px 20px 20px;">' + '<div class="smallfont" style="margin-bottom: 2px;">' +'<b>Image Spoiler:</b>' +'<input type="button" onclick="if (this.parentNode.parentNode.getElementsByTagName(\'div\')[1].getElementsByTagName(\'div\')[0].style.display != \'\') { this.parentNode.parentNode.getElementsByTagName(\'div\')[1].getElementsByTagName(\'div\')[0].style.display = \'\';this.innerText = \'\'; this.value = \'Hide\'; } else { this.parentNode.parentNode.getElementsByTagName(\'div\')[1].getElementsByTagName(\'div\')[0].style.display = \'none\'; this.innerText = \'\'; this.value = \'Show\'; }" style="margin: 0px; padding: 0px; width: 45px; font-size: 10px;" value="Show"></div><div class="alt2" style="border: 1px inset ; margin: 0px; padding: 6px;"><div style="display: none;"><br><img src="'+imageArray.eq(i).attr('src')+'" border="0" alt="">');
        imageArray.eq(i).after('<br></div></div></div>');
        imageArray.eq(i).remove();
    }
    for (var i=0; i<videoArray.length; i++){
        videoArray.eq(i).before('<div style="margin: 5px 20px 20px;">' + '<div class="smallfont" style="margin-bottom: 2px;">' +'<b>Video Spoiler:</b>' +'<input type="button" onclick="if (this.parentNode.parentNode.getElementsByTagName(\'div\')[1].getElementsByTagName(\'div\')[0].style.display != \'\') { this.parentNode.parentNode.getElementsByTagName(\'div\')[1].getElementsByTagName(\'div\')[0].style.display = \'\';this.innerText = \'\'; this.value = \'Hide\'; } else { this.parentNode.parentNode.getElementsByTagName(\'div\')[1].getElementsByTagName(\'div\')[0].style.display = \'none\'; this.innerText = \'\'; this.value = \'Show\'; }" style="margin: 0px; padding: 0px; width: 45px; font-size: 10px;" value="Show"></div><div class="alt2" style="border: 1px inset ; margin: 0px; padding: 6px;"><div style="display: none;"><br><iframe src='+videoArray.eq(i).attr('src')+'>');
        videoArray.eq(i).insertAfter('<br></div></div></div>');
        videoArray.eq(i).remove();
    }
} );