imgur.direct

Adds image direct link for imgur uploads.

目前為 2016-08-04 提交的版本,檢視 最新版本

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

You will need to install an extension such as Tampermonkey to install this script.

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         imgur.direct
// @namespace    imgurdir
// @version      0.1.0
// @description  Adds image direct link for imgur uploads.
// @author       Jakub Rychecký <[email protected]>
// @license      WTFPL 2
// @include      *imgur.com*
// ==/UserScript==


create_direct();




function create_direct(){
    $('.post-image-container').each(function(){ // Every image container
      var img = $(this);
        
      if(!has_direct_link(img) && is_image_ready(img)){ // Doesn't have direct link yet and image is fully uploaded...
          write_direct_link(img);   
      }
    });
    
    setTimeout(create_direct, 500); // Let's repeat
}



function get_direct_link(img){
   var link = img.find('a.zoom').attr('href'); // Link from zoom
   link = 'http:'+link;
    
   return link;
}


function is_image_ready(img){
  var link = get_direct_link(img);
    
  return link.indexOf('undefined') == -1 && link.indexOf('blob') == -1;
}


function has_direct_link(img){
  return img.find('.direct').length > 0;
}

function write_direct_link(img){
   var css = { // CSS for textarea
     'width': '100%',
     'background': '#2C2F34',
     'text-align': 'center',
     'font-weight': 'bold',
     'font-size': '0.8em',
     'height': '28px',
     'margin-bottom': '0px'
   }
    
   var html = $('<textarea onclick="$(this).select()">'+get_direct_link(img)+'</textarea>'); // Direct link textarea
    
   html.addClass('direct').css(css);
    
   img.prepend(html);
}