Guest User

feedly_jdownloader.user.js

a guest
Sep 29th, 2013
262
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name        feedly_jdownloader
  3. // @description feed URLs to JDownloader.
  4. // @include     http://cloud.feedly.com/*
  5. // @include     https://cloud.feedly.com/*
  6. // @version     1.0.0
  7. // ==/UserScript==
  8.  
  9. // JDownloader2の拡張設定から以下の機能のチェックを外すことを推奨
  10. // Auto Package Matching Correction
  11. //  => OFF
  12.  
  13. (function(){
  14.     var KEY_CODE = 190;     // [.]ピリオドキー
  15.     var DISPTIME = 500;     // msec
  16.  
  17.     var CSS = [
  18.         "#jddialog{ background-color: #333333; display: none; opacity: 0.8; color: #fff; top: 50%; left: 50%; max-width: 600px; width: 600px; height: 50px; margin: -150px 0px 0px -200px; padding: 20px; text-align: center; font-size : 16px; font-weight: bold; z-index: 99999; position: fixed; -moz-user-select: none; -moz-border-radius: 4px; -webkit-border-radius: 4px; border-radius: 4px;}",
  19.     ].join('');
  20.     GM_addStyle(CSS);
  21.  
  22.     function showdialog(msg){
  23.         var jddialog = document.getElementById("jddialog");
  24.         if(!jddialog){
  25.             var div = document.createElement("div");
  26.             div.id = "jddialog";
  27.             document.body.appendChild(div);
  28.             jddialog = div;
  29.         }
  30.         jddialog.textContent= msg;
  31.         jddialog.style.display = "block";
  32.         window.setTimeout(function(){
  33.             jddialog.style.display = "none";
  34.         }, DISPTIME);
  35.     }
  36.  
  37.     function form_encode(param){
  38.         var buf = [];
  39.         for(var key in param){
  40.             var value = param[key];
  41.             buf.push(
  42.                 encodeURIComponent(key)+"="+encodeURIComponent(value)
  43.             )
  44.         }
  45.         return buf.join("&");
  46.     }
  47.  
  48.     function getURLs(elm){
  49.         var buf = [];
  50.         var links = elm.getElementsByTagName("a");
  51.         for(var i = 0; i < links.length; i++){
  52. //          if(links[i].firstChild.nodeName === "#text")
  53.                 buf.push(links[i]);
  54.         }
  55.         return buf.join("\n");
  56.     }
  57.  
  58.     function add_to_jdownloader(){
  59.         var entryLists = document.getElementsByClassName("entryList");
  60.         if(!entryLists) return;
  61.  
  62.         var entry = (entryLists[0].getElementsByClassName("selectedEntry") && entryLists[0].getElementsByClassName("selectedEntry")[0]) ||
  63.                     (entryLists[0].getElementsByClassName("inlineFrame")   && entryLists[0].getElementsByClassName("inlineFrame")[0]);
  64.         if(!entry) return;
  65.  
  66.         var title = entry.getElementsByClassName("title")[0].textContent;
  67.         var body  = entry.getElementsByClassName("content")[0];
  68.  
  69.         var postdata = form_encode({
  70.             source: "feedly",
  71.             package: title,
  72.             urls: getURLs(body),
  73. //          fnames: "",
  74. //          apass: archivepass,         // archive pass
  75. //          dpass: "",                  // download pass
  76. //          autostart: "0",             // 0 or 1
  77. //          referer: "",
  78. //          descriptions: ""
  79.         });
  80.  
  81.         GM_xmlhttpRequest({
  82.             method: "post",
  83.             headers: {"Content-type": "application/x-www-form-urlencoded"},
  84.             url: "http://127.0.0.1:9666/flash/add",
  85.             data: postdata,
  86.             onload: function(res){
  87.                 if(res.status === 200 && res.responseText.indexOf("success") > -1){
  88.                     showdialog("JDownloader : " + title);
  89.                 }else{
  90.                     showdialog("JDownloader : Failed - " + res.status + " " + res.statusText);
  91.                 }
  92.             },
  93.             onerror: function(res){
  94.                 showdialog("JDownloader : Error - " + res.status + " " + res.statusText);
  95.             }
  96.         });
  97.     }
  98.  
  99.     document.addEventListener("keydown", function(e){
  100.         if(e.keyCode === KEY_CODE &&
  101.            !e.shiftKey && !e.ctrlKey && !e.altKey && !e.metaKey &&
  102.            !/^input|^textarea/i.test(e.target.tagName)){
  103.                add_to_jdownloader();
  104.            }
  105.         }
  106.     );
  107. })();
Add Comment
Please, Sign In to add comment