view tweetdeck-large-image.user.js @ 50:e8517cc75a74

Add https, update coding style
author nanaya <me@nanaya.pro>
date Fri, 13 Oct 2017 02:40:23 +0900
parents 2e1cae72a63e
children 19c391840d4a
line wrap: on
line source

// ==UserScript==
// @name         Tweetdeck large image
// @namespace    https://myconan.net
// @version      1.0.2
// @description  No more stupid link for images in tweetdeck
// @author       nanaya
// @match        https://tweetdeck.twitter.com/*
// @grant        none
// @downloadURL  https://bitbucket.org/!api/2.0/snippets/nanayapro/TK64/tip/files/tweetdeck-large-image.user.js
// ==/UserScript==

;(function() {
  "use strict";

  var $ = jQuery;
  var replaceLink = function(e) {
    var link = e.currentTarget;
    if (link._ecUserscript === true) { return; }
    
    var images = link.getElementsByClassName("media-img");
    
    var url;
    if (images.length) {
      url = images[0].src.replace(/:[a-z0-9]+$/, "");
    } else {
      url = getComputedStyle(link).backgroundImage.replace(/^url\(('|")?(.+?)(:small)?\1\)$/, "$2");
    }
    link.setAttribute("href", url + ":orig");
    link._ecUserscript = true;
  };
  
  $(document).off(".ec-userscript");
  $(document).on("mouseenter.ec-userscript", ".js-media-image-link", replaceLink);
}).call();