Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name Dvach Image Options
- // @version 0.2
- // @description Adds direct download button and reverse image search options
- // @author Π΅ΠΌΡ
- // @match https://2ch.hk/*/res/*
- // @require https://code.jquery.com/jquery-3.2.1.min.js
- // @resource fa_CSS https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css
- // @grant GM_addStyle
- // @grant GM_getResourceText
- // ==/UserScript==
- this.$ = this.jQuery = jQuery.noConflict(true);
- GM_addStyle(GM_getResourceText("fa_CSS"));
- GM_addStyle(".image-reverse { text-decoration:none;margin-left:4px;color:#666666;font-size:10px; } .image-reverse:hover { text-decoration: underline; } .image-direct-download { text-decoration:none;margin-left:4px;font-size:14px; }");
- function getReverseImageSearchOptions(url)
- {
- var options = {
- 'google': 'https://www.google.com/searchbyimage?image_url=' + url + '&safe=off',
- 'yandex': 'https://www.yandex.com/images/search?rpt=imageview&img_url=' + url,
- 'iqdb': 'https://iqdb.org/?url=' + url
- };
- return options;
- }
- var re = new RegExp('(mp4|webm)');
- function onElementHeightChange(elm, callback)
- {
- var lastHeight = elm.clientHeight, newHeight;
- (function run()
- {
- newHeight = elm.clientHeight;
- if(lastHeight != newHeight)
- callback();
- lastHeight = newHeight;
- if(elm.onElementHeightChangeTimer)
- clearTimeout(elm.onElementHeightChangeTimer);
- elm.onElementHeightChangeTimer = setTimeout(run, 1000);
- })();
- }
- function applyOptions()
- {
- $(".file-attr").each(function(index)
- {
- if($(this).find('.image-options').length > 0)
- {
- return;
- }
- var file_url = $(this).find('a');
- if(file_url != undefined)
- {
- $reverse_options = getReverseImageSearchOptions(document.location.origin + file_url.attr('href'));
- if (re.test(file_url.attr('href'))) {
- $preview = $(this).parent().find('.preview');
- if($preview.length > 0)
- {
- if($preview.attr('src') != undefined)
- {
- $reverse_options = getReverseImageSearchOptions(document.location.origin + $preview.attr('src'));
- }
- }
- }
- var first_c = $(this).find(">:first-child");
- var direct_download = '<a class="fa fa-download image-direct-download" href="' + file_url.attr('href') + '" download="' + file_url.attr('title') + '"></a>';
- var r_google = '<a target="_blank" href="' + $reverse_options['google'] + '" class="image-reverse">google</a>';
- var r_yandex = '<a target="_blank" href="' + $reverse_options['yandex'] + '" class="image-reverse">yandex</a>';
- first_c.after('<div class="image-options" style="display:inline-block;">' + direct_download + r_google + r_yandex + '</div>');
- }
- });
- }
- $(document).ready(function()
- {
- onElementHeightChange(document.body, function(){
- applyOptions();
- });
- applyOptions();
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement