From 7282f127cc4c6236a98679c0e23ee5113dde6b26 Mon Sep 17 00:00:00 2001 From: Dmitry Date: Fri, 29 Apr 2016 20:52:34 +0300 Subject: [PATCH] NO MORE CORS Get rid of this crap entirely. No more relying on the unstable proxies with no uptime, no more FF problems with script loading. I should have thought of simply putting the entire html page into a .js file earlier. Where are your security limitations now? Since jQuery isn't needed anymore either, the support for Opera is back as well. It's a real pity I can't use the same approach in my MSL project. --- booru.mass.uploader.user.js | 84 +++++------ index.html | 21 +-- js/index.html.js | 275 ++++++++++++++++++++++++++++++++++++ 3 files changed, 313 insertions(+), 67 deletions(-) create mode 100644 js/index.html.js diff --git a/booru.mass.uploader.user.js b/booru.mass.uploader.user.js index 66457bd..4e3587b 100644 --- a/booru.mass.uploader.user.js +++ b/booru.mass.uploader.user.js @@ -2,7 +2,7 @@ // @name Booru Mass Uploader // @description Add ability to bulk upload images to your booru // @namespace https://github.com/Seedmanc/Booru-mass-uploader -// @version 1.3.2 +// @version 1.3.3 // @author Seedmanc // @include http://*.booru.org/index.php* // @include http://rule34.xxx/index.php* @@ -13,82 +13,64 @@ // @include https://chan.sankakucomplex.com/* // @include http://atfbooru.ninja/* // @include http://danbooru.donmai.us/* +// @include http://eikonos.org/* // you can add any boorus of your choice by following the pattern // @grant none // @run-at document-end // @noframes - -// @require https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js // ==/UserScript== if (window.top != window.self) { throw 'no iframes'; } -var corses = ['www.whateverorigin.org/get?url=', 'crossorigin.me/']; - -function onSuccess(response) { - var scripts; - - document.getElementsByTagName('body')[0].innerHTML = response; - scripts = document.getElementsByTagName('script'); - - for (var i = 0; i < scripts.length; i++) { - var node = scripts[i], parent = node.parentElement, d = document.createElement('script'); - - d.async = node.async; - d.src = node.src; - parent.insertBefore(d, node); - parent.removeChild(node); - } +function activateScripts(scripts, i) { + var node = scripts[i], + parent = node.parentElement, + d = document.createElement('script'); + + d.async = node.async; + d.src = node.src; + d.onload = function () { + if (i < scripts.length - 1) { + activateScripts(scripts, i + 1); + } + }; + parent.insertBefore(d, node); + parent.removeChild(node); } -function tryCors(idx) { - - idx = idx || 0; - - if (!corses[idx]) { - document.write('Ran out of CORS engines, try later'); - return; - } +if (~document.location.href.indexOf('s=mass_upload')) { + var script = document.createElement('script'); - (idx ? $.get : $.getJSON)(location.protocol + '//' + corses[idx] + 'http://seedmanc.github.io/Booru-mass-uploader/index.html' + (idx ? '' : '&callback=?')) - .done(function (response) { - onSuccess(response.contents || response); - }) - .fail(function (response) { - if (response.status == 200 && response.readyState == 4) { - onSuccess(response.responseText); - } else { - console.log(response); - tryCors(idx + 1); - } - }); -} + document.body.innerHTML = ''; + script.src = 'https://seedmanc.github.io/Booru-mass-uploader/js/index.html.js'; + script.onload = function () { + var scripts = document.getElementsByTagName('script'); -if (~document.location.href.indexOf('s=mass_upload')) { - document.write(''); - tryCors(); + activateScripts(scripts, 0); + }; + document.body.appendChild(script); } else { - var navbar = $('#navbar')[0] || - $('.flat-list2')[0] || - $('#main-menu > ul')[0] || - $('nav > menu')[0]; + var navbar = document.getElementById('navbar') || + document.getElementsByClassName('flat-list2')[0] || + document.querySelector('#main-menu > ul') || + document.querySelector('nav > menu'); var li = document.createElement("li"); var a = document.createElement("a"); - var token = $('meta[name="csrf-token"]')[0]; + var token = document.querySelector('meta[name="csrf-token"]'); token = token && token.content; if (token) { localStorage.setItem('auth_token', token); } - if ($('[src*="moe-legacy"]').length || $('html.action-post').length || $('[href*="/post/upload"]').length) { + if (document.querySelector('[src*="moe-legacy"]') || document.querySelector('html.action-post') || document.querySelector('[href*="/post/upload"]')) { localStorage.setItem('current', 'moebooru'); - } else if ($('[href*="/uploads/new"]').length || ~document.documentElement.innerHTML.indexOf('Running Danbooru')) { + } else if (document.querySelector('[href*="/uploads/new"]') || ~document.documentElement.innerHTML.indexOf('Running Danbooru')) { localStorage.setItem('current', 'danbooru'); } @@ -101,4 +83,4 @@ if (~document.location.href.indexOf('s=mass_upload')) { a.href = document.location.protocol + '//' + document.location.hostname + '/index.php?page=post&s=mass_upload'; li.appendChild(a); navbar.appendChild(li); -} +} \ No newline at end of file diff --git a/index.html b/index.html index 49f5b48..b8d6421 100644 --- a/index.html +++ b/index.html @@ -17,7 +17,7 @@ } p.intro, q { - font-style: italic; + font-weight: bold; } fieldset { @@ -131,20 +131,9 @@ -

Booru Mass-Uploader - -

-

This script allows you to mass-upload images to imageboard sites running *booru software. - Select a number of files and they're sent to the website along with the metadata you include such as - the tags retrived from the filenames.

+

You need to update + to Win10

+

Support for the old version will be dropped by next release. The new version finally fixes the white screen/HTTPS unavailability/FF loading issues for good.

@@ -276,7 +265,7 @@

Booru Mass-Uploader
loading - +

diff --git a/js/index.html.js b/js/index.html.js new file mode 100644 index 0000000..203b596 --- /dev/null +++ b/js/index.html.js @@ -0,0 +1,275 @@ +document.documentElement.innerHTML='\ +\ + Mass uploader\ + \ + \ + \ + \ + \ + \ + \ + \ +\ +\ +

Booru Mass-Uploader v1.3.3

\ +

This script allows you to mass-upload images to imageboard sites running *booru software.\ + Select a number of files and they\'re sent to the website along with the metadata you include such as\ + the tags retrived from the filenames.

\ +\ +
\ + \ + Filename syntax for correct uploads\ + \ + [+/-]\ + \ + \ +\ + \ +
\ +\ +
\ + Image ratings\ +\ +
\ + \ + \ + \ + \ +
\ +\ +
\ + \ + \ + \ + \ + \ + \ +
\ +
\ +\ +
\ + Tagging\ +\ + \ + \ +
\ +\ + \ + \ +
\ +\ +
\ + Tag list (separate with spaces):\ + \ +
\ + \ +
\ +\ +
\ + \ + Other settings\ + \ + [+/-]\ + \ + \ +\ +
\ +
\ +
\ + \ + \ +
\ +
\ + Set Source field of each image to\ + \ +
\ +
\ +
\ + Select booru engine: \ + \ + \ +
\ +
\ +
\ +
Selection mode:\ + \ + \ + \ + \ +
\ +
\ + Images:\ +
\ + (All files with MIME types other than image/* and\ + extension other than jpg/jpeg/gif/png will be skipped)\ +
\ +
\ +loading\ +\ +\ +\ +

\ +
\ +
\ +
\ +\ +\ +'; \ No newline at end of file