Skip to content
This repository has been archived by the owner on Aug 27, 2024. It is now read-only.

Commit

Permalink
NO MORE CORS
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Seedmanc committed Apr 29, 2016
1 parent 8f6916c commit 7282f12
Show file tree
Hide file tree
Showing 3 changed files with 313 additions and 67 deletions.
84 changes: 33 additions & 51 deletions booru.mass.uploader.user.js
Original file line number Diff line number Diff line change
Expand Up @@ -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*
Expand All @@ -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 = '<img src="https://seedmanc.github.io/Booru-mass-uploader/spinner.gif"/>';
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('<img src="https://seedmanc.github.io/Booru-mass-uploader/spinner.gif"/>');
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');
}

Expand All @@ -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);
}
}
21 changes: 5 additions & 16 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
}

p.intro, q {
font-style: italic;
font-weight: bold;
}

fieldset {
Expand Down Expand Up @@ -131,20 +131,9 @@
<script type="text/javascript" src="https://seedmanc.github.io/Booru-mass-uploader/js/uploader.js"></script>
</head>
<body>
<h1>Booru Mass-Uploader
<a href="#" style="text-decoration:none; font-size:20px; vertical-align:middle; opacity:0.75;" onclick=
"if (document.body.style.width == '66%') {
document.body.style.width = '95%';
document.getElementById('source').style.width = '500px';
} else {
document.body.style.width = '66%';
document.getElementById('source').style.width = '200px';
};"
>&harr;</a>
</h1>
<p class="intro">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.</p>
<h1>You need to <a href="https://github.com/Seedmanc/Booru-mass-uploader/raw/gh-pages/booru.mass.uploader.user.js">update</a>
<span style="font-size:15px; text-decoration: line-through;"> to Win10</span></h1>
<p class="intro">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.</p>

<fieldset style="padding: 2px 1em">
<legend>
Expand Down Expand Up @@ -276,7 +265,7 @@ <h1>Booru Mass-Uploader
<br>
<img src="https://seedmanc.github.io/Booru-mass-uploader/spinner.gif" id="spinner" alt="loading"/>
<p style="display: none;" id="infobar">You are <b id="loggedIn"></b> to a <b id="current"></b> site.</p>
<button disabled="" id="submit" onclick="FilesSelected( $('files').files );">Upload!</button>
<button disabled="" id="submit" onclick="FilesSelected($('files').files );">Upload!</button>

<h2 id="status"></h2>
<div id="progressWr">
Expand Down
Loading

0 comments on commit 7282f12

Please sign in to comment.