Skip to content
This repository has been archived by the owner on May 30, 2021. It is now read-only.

Commit

Permalink
Added more parts; fixed some bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
MegaApuTurkUltra committed Mar 11, 2015
1 parent e474ac3 commit fb72413
Show file tree
Hide file tree
Showing 4 changed files with 122 additions and 15 deletions.
9 changes: 6 additions & 3 deletions msu-base.user.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@
// @include http://wiki.scratch.mit.edu/*
// @include https://wiki.scratch.mit.edu/*
// @version 1.1.0
// @website https://megascratchuserscript.github.io
// @grant unsafeWindow
// @grant GM_getResourceText
// @grant GM_addStyle
// @grant GM_getValue
// @grant GM_setValue
// @icon https://cdn.rawgit.com/MegaScratchUserscript/Mega-Scratch-Userscript/master/resources/icon.png
// @resource settingshtml resources/settings.htmlpart
// @resource settingscss resources/settings.css
// @resource settingscss2 resources/settings2.css
// @resource theme resources/theme.csspart
// @require https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js
// @require https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/jquery-ui.min.js
Expand All @@ -31,11 +32,13 @@
// @require parts/profileenhancer.part.js
// @require parts/wikilink.part.js
// @require parts/scratchtheme.part.js
// @require parts/spoiler.part.js
// @require parts/projectStuff.part.js
// ==/UserScript==

// I called this base.user.js in case this is the main script
var ScratchUserscript = {
MODE_DEV: false, // change to false in the release; use this flag to print data to console for debug, etc
MODE_DEV: true, // change to false in the release; use this flag to print data to console for debug, etc
_settingsHTML: $("<div id='msu-settings-dialog' title='MegaScratchUserscript Settings'></div>"),
_partsEnabled: {},
_init: function(){
Expand All @@ -55,7 +58,7 @@ var ScratchUserscript = {
ScratchUserscript._settingsHTML.css("display","none").appendTo(document.body).dialog({dialogClass:"jqui-modal", autoOpen: false, width: 800, height: 550});
$("#msu-settings-dialog").parent().append('<iframe class="iframeshim" frameborder="0" scrolling="no">&lt;html&gt;&lt;head&gt;&lt;/head&gt;&lt;body&gt;&lt;/body&gt;&lt;/html&gt;</iframe>');
ScratchUserscript._settingsHTML.html(GM_getResourceText("settingshtml"));
GM_addStyle(GM_getResourceText("settingscss"));
GM_addStyle(GM_getResourceText("settingscss2"));
var openSettings = $("<a href='javascript:void(0)'><acronym title='Mega Scratch Userscript'>MSU</acronym> Settings</a>");
openSettings.click(function(){
ScratchUserscript._settingsHTML.dialog("open");
Expand Down
97 changes: 97 additions & 0 deletions parts/projectStuff.part.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
msuParts["projectStuff"] = function (ScratchUserscript) {
var settingsDlg = $("<div></div>");

ScratchUserscript.registerPart("Project Stuff", "Adds phosphorus and scratchblocks2 buttons to projects.", settingsDlg);

var settings = {
phosphorus: true,
sb2: true,
diff: true
};
var labels = {
phosphorus: "Enable phosphorus button",
sb2: "Enable scratchblocks2 generator button",
diff: "Enable scratchblocks2 diff button"
};
settings = ScratchUserscript.readSetting("projectStuff", "settings", settings);

updateChanges = function(){
for(x in settings){
if($("#msu-ps"+x+"btn").is(":checked")){
settings[x] = true;
} else {
settings[x] = false;
}
}
ScratchUserscript.writeSetting("projectStuff", "settings", settings);
};

settingsDlg.append("<br/>");

for(x in settings){
settingsDlg.append("<input type='checkbox' id='msu-ps"+x+"btn' /> \
<label for='msu-ps"+x+"btn' \
style='display: inline;margin-right:1em;'>\
"+labels[x]+"</label><br/>");
if(settings[x]) $("#msu-ps"+x+"btn").attr("checked", "checked");
}

settingsDlg.find("input").bind("change", updateChanges);

var isEnabled = ScratchUserscript.isPartEnabled("projectStuff");

if (isEnabled && ScratchUserscript.getPageType().type == "project") {
if(settings.phosphorus){
var phosButton = $('<div id="msu-ps-phosphorus" class="action tooltip bottom isflash">'+
'<span class="hovertext" id="msu-ps-phosphorus-tool"><span class="arrow"></span>Switch to phosphorus</span>'+
'<span>Player type</span></div>');
$(".active").append(phosButton);
$("#msu-ps-phosphorus").click(function(){
if($(this).hasClass('isflash')){
$(this).removeClass('isflash');
$(".buttons").hide();
$(".player").hide();

var iframe = document.createElement('iframe');
iframe.setAttribute('allowfullscreen', true);
iframe.setAttribute('allowtransparency', true);
iframe.src = 'http://phosphorus.github.io/embed.html?id=' + Scratch.INIT_DATA.PROJECT.model.id + '&auto-start=true&light-content=false';
iframe.width = 482;
iframe.height = 393;
iframe.style.border = '0';
iframe.className = 'phosphorus';
var first = document.getElementsByClassName('player')[0];
first.parentNode.insertBefore(iframe, first);

$("#msu-ps-phosphorus-tool").html("<span class='arrow'></span>Switch to flash");
} else {
$(this).addClass('isflash');
$(".buttons").show();
$(".player").show();
$(".msu-phosphorus-script, .phosphorus").remove();
$("#msu-ps-phosphorus-tool").htmk("<span class='arrow'></span>Switch to phosphorus");
}
});
}
if(settings.sb2){
var btn = $('<div id="msu-ps-sb2" class="action tooltip bottom isflash">'+
'<span class="hovertext"><span class="arrow"></span>Generate scratchblocks2 code</span>'+
'<span>Generate code</span></div>');
$(".active").append(btn);
$("#msu-ps-sb2").click(function(){
window.open('http://scratchblocks.github.io/generator/#project='+Scratch.INIT_DATA.PROJECT.model.id, "_blank");
});
}
if(settings.diff){
var btn = $('<div id="msu-ps-diff" class="action tooltip bottom isflash">'+
'<span class="hovertext"><span class="arrow"></span>Generate scratchblocks2 diff</span>'+
'<span>Generate diff</span></div>');
$(".active").append(btn);
$("#msu-ps-diff").click(function(){
var diff2 = prompt("Other project ID?");
if(diff2 == null || diff2 == "") return;
window.open('http://scratchblocks.github.io/diff/#'+Scratch.INIT_DATA.PROJECT.model.id+"+"+diff2, "_blank");
});
}
}
};
27 changes: 17 additions & 10 deletions parts/spoiler.part.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,34 @@
msuParts["spoiler"] = function (ScratchUserscript) {
var settingsDlg = $("<div></div>");
var settingsDlg = $("<div><i>Put [color=spoiler] Hello! [/color] in a forum post to make a spoiler!<br/>Also supports [color=transparent][/color]</i></div>");

ScratchUserscript.registerPart("Forum Spoilers", "Put [color=spoiler] Hello! [/color] in a forum post to make a spoiler!", settingsDlg);
ScratchUserscript.registerPart("Forum Spoilers", "Adds support for spoilers to forums.", settingsDlg);

var isEnabled = ScratchUserscript.isPartEnabled("spoiler");

if (isEnabled) {
// actual script
$(document).ready(function() {
$('.postright span').each(function(index) {
if($(this).attr('style')==='color:spoiler') {
$('<a class="revealTag" id="openspoiler' + index + '">Open spoiler &gt;&gt;</a> ').insertBefore(this);
if($(this).attr('style')==='color:spoiler' || $(this).attr('style')==='color:transparent') {
var make = $(this).html();
$(this).html('<span id="spoiler' + index + '">' + make + '</span>').hide();
if($(this).attr('style')==='color:transparent'){
$(this).css("color", "initial");
}
$(this).html('<blockquote><span class="bb-quote-author revealTag spoiler_closed" id="openspoiler'+index+'">'+
"Open Spoiler &gt;&gt;"+
'</span><div id="spoiler' + index + '" style="display:none">' + make + '</div></blockquote>');
}
});

$("a.revealTag").click(function() {
$(".revealTag").css({"cursor":"pointer","text-decoration":"underline"}).click(function() {
var thing = $(this).attr('id').substring(11, $(this).attr('id').length);

$( '#spoiler' + thing ).parent().css('display', 'inherit');

$(this).remove();
if($(this).hasClass("spoiler_closed")){
$(this).html("Close Spoiler &lt;&lt;").removeClass("spoiler_closed");
$('#spoiler' + thing).slideDown();
} else {
$(this).html("Open Spoiler &gt;&gt;").addClass("spoiler_closed");
$('#spoiler' + thing).slideUp();
}
});
});
}
Expand Down
4 changes: 2 additions & 2 deletions resources/settings.css → resources/settings2.css
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

.msu-settings-note {
position: absolute;
bottom: 10px;
bottom: 0px;
left: 10px;
}

Expand Down Expand Up @@ -35,7 +35,7 @@
border: 1px solid gray;
border-bottom: none;
border-right: none;
padding: 10px;
padding: 0.3em;
margin-right: 0;
margin-bottom: 0;
transition: background 0.5s;
Expand Down

0 comments on commit fb72413

Please sign in to comment.