ImgURL.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. // ==UserScript==
  2. // @name ImgURL上传脚本
  3. // @namespace https://imgurl.org/
  4. // @version 0.21
  5. // @description ImgURL快捷上传工具
  6. // @author xiaoz.me
  7. // @match http://*/*
  8. // @match https://*/*
  9. // @license GPL
  10. // @grant none
  11. // ==/UserScript==
  12. (function() {
  13. 'use strict';
  14. //定义一个全局弹出层
  15. window.layerstart = '<div id = "layer" style = "box-shadow: 1px 1px 2px #888888;border-radius:5px;top:0em;left:0;width:80%;height:720px;background-color:#FFFFFF;position:fixed;z-index:999;display:none;border:1px solid #d2d2d2">';
  16. layerstart += '<div style="text-align:right;padding:0.8em;border-bottom:1px solid #d2d2d2;"><a href="javascript:;" onclick="closelayer()" style="color:#FFFFFF;background-color:#FF5722;width:80px;text-align:center;padding:0.5em;border-radius:2px;padding-left:1em;padding-right:1em;">关闭</a></div>';
  17. window.layerend = '</div>';
  18. //让层居中显示
  19. window.layerCenter = function(){
  20. var bwidth = window.screen.availWidth;
  21. var bheight = window.screen.availHeight;
  22. var layertop = (bheight - 720) / 2;
  23. var layerleft = (bwidth - 1280) / 2;
  24. if(layertop <= 70){
  25. layertop = "1em";
  26. }
  27. else{
  28. layertop = layertop + "px";
  29. }
  30. //改变css
  31. //$("#layer").css({"top":layertop,"left":layerleft});
  32. //原生js改变css
  33. //alert(layertop);
  34. document.getElementById("layer").style.top = layertop;
  35. document.getElementById("layer").style.left = "10%";
  36. }
  37. //创建一个遮罩层
  38. window.keepout = function(){
  39. var fade = '<div id = "fade" style = "width:100%;height:100%;background:rgba(0, 0, 0, 0.5);position: fixed;left: 0;top: 0;z-index: 99;" onclick = "closelayer()"></div>';
  40. //$("body").append(fade);
  41. var div = document.createElement("div");
  42. div.innerHTML = fade;
  43. document.body.appendChild(div);
  44. }
  45. //关闭层
  46. window.closelayer = function(){
  47. //$("#layer").hide();
  48. document.getElementById("layer").style.display = "none";
  49. //showSidebar();
  50. //$("#layer").remove();
  51. var layer = document.getElementById("layer");
  52. layer.parentNode.removeChild(layer);
  53. //$("#fade").remove();
  54. var fade = document.getElementById("fade");
  55. fade.parentNode.removeChild(fade);
  56. }
  57. //创建一个显示按钮
  58. function imgurl(){
  59. //$("body").append('<div id = "imgbtn" style = "position:fixed;right:1em;bottom:1em;z-index:88;cursor:pointer;" onclick = "showImgurl()"><img src = "https://libs.xiaoz.top/material/image.png" width = "36px" height = "36px" /></div>');
  60. //使用原生js添加按钮
  61. var div = document.createElement("div");
  62. div.innerHTML = '<div id = "imgbtn" style = "position:fixed;right:1em;bottom:1em;z-index:88;cursor:pointer;" onclick = "showImgurl()"><img src = "https://libs.xiaoz.top/material/image.png" width = "36px" height = "36px" /></div>';
  63. document.body.appendChild(div);
  64. }
  65. //显示上传按钮
  66. window.showImgurl = function(){
  67. var up = layerstart;
  68. up += '<iframe src = "https://imgurl.org/miniup.html" width="100%" height="660px" frameborder="0"></iframe>';
  69. up += layerend;
  70. //$("body").append(up);
  71. var div = document.createElement("div");
  72. div.innerHTML = up;
  73. document.body.appendChild(div);
  74. //$("#layer").show();
  75. document.getElementById("layer").style.display = "block";
  76. //显示遮罩
  77. keepout();
  78. //居中显示层
  79. layerCenter();
  80. }
  81. imgurl();
  82. })();