Image drag-n-drop uploader for vozforums.net

Upload image without watermarking for vozforums.net

  1. // ==UserScript==
  2. // @name Image drag-n-drop uploader for vozforums.net
  3. // @version 1.3
  4. // @description Upload image without watermarking for vozforums.net
  5. // @namespace image-uploader-voz
  6. // @author Huy không at fb.me/huykhoong
  7. // @run-at document-end
  8. // @grant GM_addStyle
  9. // @grant GM_getResourceText
  10. // @resource dropzone http://phpvenus.com/voz/dropzone.css
  11.  
  12. // Website list
  13.  
  14. // @match *://*.vozforums.com/*
  15.  
  16. // End list
  17.  
  18.  
  19. // ==/UserScript==
  20. //
  21. var jqUI_CssSrc = GM_getResourceText ("dropzone");
  22. GM_addStyle (jqUI_CssSrc);
  23.  
  24. function addJQuery(callback) {
  25. var script = document.createElement("script");
  26. script.setAttribute("src", "//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js");
  27. script.addEventListener('load', function() {
  28. var script = document.createElement("script");
  29. script.textContent = "window.jQ=jQuery.noConflict(true);(" + callback.toString() + ")();";
  30. document.body.appendChild(script);
  31. }, false);
  32. document.body.appendChild(script);
  33. }
  34.  
  35. function addGlobalStyle(css) {
  36. var head, style;
  37. head = document.getElementsByTagName('head')[0];
  38. if (!head) { return; }
  39. style = document.createElement('style');
  40. style.type = 'text/css';
  41. style.innerHTML = css;
  42. head.appendChild(style);
  43. }
  44.  
  45. // the guts of this userscript
  46. function main() {
  47. jQ.cachedScript = function( url, options ) {
  48. // Allow user to set any option except for dataType, cache, and url
  49. options = jQ.extend( options || {}, {
  50. dataType: "script",
  51. cache: true,
  52. url: url
  53. });
  54. // Use jQ.ajax() since it is more flexible than jQ.getScript
  55. // Return the jqXHR object so we can chain callbacks
  56. return jQ.ajax( options );
  57. };
  58. // Usage
  59. jQ.cachedScript( "http://phpvenus.com/voz/dropzone.js" ).done(function( script, textStatus ) {
  60. jQ('div.dz-message').html('<b>Công cụ upload ảnh.</b><br><span class="note">Kéo thả ảnh hoặc click vào khung này</span> ');
  61. Dropzone.autoDiscover = false;
  62. var md = new Dropzone("#mydropzone", {
  63. init: function() {
  64. this.on("addedfile", function(file) { });
  65. this.on("success", function(file, response) {
  66. if(response.indexOf('http') > -1){
  67. var textarea = document.querySelector('.vBulletin_editor textarea');
  68. textarea.value += '[IMG]'+response+'[/IMG]' + "\n";
  69. }else{
  70. alert(response);
  71. }
  72. });
  73. },
  74. method: 'post',
  75. url: "http://phpvenus.com/voz/uploader.php",
  76. maxFilesize: "5",
  77. addRemoveLinks: true,
  78. paramName: "file",
  79. maxFiles : "10",
  80. previewsContainer: null,
  81. autoProcessQueue : true
  82. });
  83. });
  84.  
  85. }
  86.  
  87. function add_uploader(){
  88. var t = jQ("a[href='http://pik.vn/']").first().parent();
  89. t.append('<div id="dropzone"><form action="/file-upload" class="dropzone" id="mydropzone"><div class="dz-message">Đang tải ...</div></form></div>');
  90. }
  91.  
  92. // load jQuery and execute the main function
  93. //
  94. addGlobalStyle('#dropzone{margin-top:10px');
  95. addGlobalStyle('.dropzone { border: 2px dashed #0087F7; border-radius: 5px; background: white; padding:10px;');
  96. addGlobalStyle('.dropzone .dz-preview { margin: 5px; }');
  97. addGlobalStyle('.dz-remove{display:none !important}');
  98. addJQuery(add_uploader);
  99. addJQuery(main);