Skip to content

Commit

Permalink
This is only a test... MKII
Browse files Browse the repository at this point in the history
*drops the mic*
  • Loading branch information
Moebius-Strip authored and Moebius-Strip committed Feb 7, 2016
1 parent 0d74626 commit 29f7da5
Showing 1 changed file with 38 additions and 21 deletions.
59 changes: 38 additions & 21 deletions better-better-booru.user.js
Original file line number Diff line number Diff line change
Expand Up @@ -1119,7 +1119,10 @@ function bbbScript() { // This is needed to make this script work in Chrome.
activeThumb.bbbAddClass("current-post");

// Make the show/hide links work.
previewLink.addEventListener("click", function(event) {
newNotice.addEventListener("click", function(event) {
if (event.target !== previewLink)
return;

if (thumbDiv.style.display === "block") {
thumbDiv.style.display = "none";
previewLink.innerHTML = "show »";
Expand All @@ -1132,7 +1135,8 @@ function bbbScript() { // This is needed to make this script work in Chrome.
}

event.preventDefault();
}, false);
event.stopPropagation();
}, true);

// Prepare thumbnails.
prepThumbnails(newNotice);
Expand Down Expand Up @@ -1168,8 +1172,8 @@ function bbbScript() { // This is needed to make this script work in Chrome.

// Append the necessary script.
var mainScript = document.createElement("script");
mainScript.src = "/assets/ugoira_player.js";
mainScript.addEventListener("load", ugoiraInit, true); // Wait for this script to load before running the JavaScript that requires it.
mainScript.src = "/assets/ugoira_player.js";
document.head.appendChild(mainScript);
}
}
Expand Down Expand Up @@ -3282,8 +3286,8 @@ function bbbScript() { // This is needed to make this script work in Chrome.
function noteToggleInit() {
// Override Danbooru's image click handler for toggling notes with a custom one.
document.addEventListener("click", function(event) {
if (event.target.id === "image" && event.button === 0 && !bbb.post.translation_mode) {
if (!bbb.drag_scroll.moved)
if (event.target.id === "image" && event.button === 0) {
if (!bbb.post.translation_mode && !bbb.drag_scroll.moved)
Danbooru.Note.Box.toggle_all();

event.stopPropagation();
Expand Down Expand Up @@ -3329,17 +3333,26 @@ function bbbScript() { // This is needed to make this script work in Chrome.
if (document.getElementById("note-locked-notice"))
return;

// Make the link toggling work for hidden posts.
if (post.is_hidden) {
if (translateLink)
translateLink.addEventListener("click", Danbooru.Note.TranslationMode.toggle, false);
}

// Script translation mode events and tracking used to resolve timing issues.
bbb.post.translation_mode = Danbooru.Note.TranslationMode.active;

if (translateLink)
translateLink.addEventListener("click", translationModeToggle, false);
// Override Danbooru's toggle function which may or may not exist depending on caching.
if (translateLink) {
var translateLinkParent = translateLink.parentNode;

toggleFunction = function(event) {
if (event.target !== translateLink)
return;

Danbooru.Note.TranslationMode.toggle(event);
translationModeToggle();

event.preventDefault();
event.stopPropagation();
};

translateLinkParent.addEventListener("click", toggleFunction, true);
}
}
else { // Allow note viewing on ugoira webm video samples, but don't allow editing.
toggleFunction = function(event) {
Expand Down Expand Up @@ -3439,8 +3452,8 @@ function bbbScript() { // This is needed to make this script work in Chrome.

if (post.has_large) {
document.addEventListener("click", function(event) {
if (event.target.id === "image" && event.button === 0 && !bbb.post.translation_mode) {
if (!bbb.drag_scroll.moved)
if (event.target.id === "image" && event.button === 0) {
if (!bbb.post.translation_mode && !bbb.drag_scroll.moved)
swapPost();

event.stopPropagation();
Expand Down Expand Up @@ -7749,8 +7762,8 @@ function bbbScript() { // This is needed to make this script work in Chrome.
hotkey.func(event); // The event object will always be the first argument passed to the provided function (previously declared or anonymous).

if (!customHandler) {
event.stopPropagation();
event.preventDefault();
event.stopPropagation();
}
}
}, true);
Expand Down Expand Up @@ -9198,10 +9211,10 @@ function bbbScript() { // This is needed to make this script work in Chrome.
return "bbbuid" + bbb.uId;
}


} // End of bbbScript.

function runBBBScript() {
// Run the script or prep it to run when Danbooru's JS is ready.
if (document.readyState === "interactive" && typeof(Danbooru) === "undefined") {
var danbScripts = document.getElementsByTagName("script");

Expand All @@ -9210,7 +9223,7 @@ function runBBBScript() {
var curScriptSrc = curScript.src || "";

if (curScriptSrc.indexOf("donmai.us/assets/application-") > -1) {
curScript.addEventListener("load", bbbScript);
curScript.addEventListener("load", bbbScript, true);
break;
}
}
Expand All @@ -9220,8 +9233,12 @@ function runBBBScript() {
}

function testBBBAccess() {
// Check whether the script has access to the page.
if (!document.body)
return;

function testFunc() {
window.bbb_local = true;
window.bbb_access = true;
}

var testScript = document.createElement('script');
Expand All @@ -9230,14 +9247,14 @@ function testBBBAccess() {
document.body.appendChild(testScript);
window.setTimeout(function() { document.body.removeChild(testScript); }, 0);

if (!window.bbb_local) {
if (!window.bbb_access) { // Embed the script since it can't get to Danbooru's JS.
var script = document.createElement('script');
script.type = "text/javascript";
script.appendChild(document.createTextNode(bbbScript));
script.appendChild(document.createTextNode('(' + runBBBScript + ')();'));
document.body.appendChild(script);
}
else
else // Operate normally.
runBBBScript();
}

Expand Down

0 comments on commit 29f7da5

Please sign in to comment.