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

Commit fb72413

Browse files
author
MegaApuTurkUltra
committed
Added more parts; fixed some bugs
1 parent e474ac3 commit fb72413

File tree

4 files changed

+122
-15
lines changed

4 files changed

+122
-15
lines changed

msu-base.user.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,15 @@
77
// @include http://wiki.scratch.mit.edu/*
88
// @include https://wiki.scratch.mit.edu/*
99
// @version 1.1.0
10+
// @website https://megascratchuserscript.github.io
1011
// @grant unsafeWindow
1112
// @grant GM_getResourceText
1213
// @grant GM_addStyle
1314
// @grant GM_getValue
1415
// @grant GM_setValue
1516
// @icon https://cdn.rawgit.com/MegaScratchUserscript/Mega-Scratch-Userscript/master/resources/icon.png
1617
// @resource settingshtml resources/settings.htmlpart
17-
// @resource settingscss resources/settings.css
18+
// @resource settingscss2 resources/settings2.css
1819
// @resource theme resources/theme.csspart
1920
// @require https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js
2021
// @require https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/jquery-ui.min.js
@@ -31,11 +32,13 @@
3132
// @require parts/profileenhancer.part.js
3233
// @require parts/wikilink.part.js
3334
// @require parts/scratchtheme.part.js
35+
// @require parts/spoiler.part.js
36+
// @require parts/projectStuff.part.js
3437
// ==/UserScript==
3538

3639
// I called this base.user.js in case this is the main script
3740
var ScratchUserscript = {
38-
MODE_DEV: false, // change to false in the release; use this flag to print data to console for debug, etc
41+
MODE_DEV: true, // change to false in the release; use this flag to print data to console for debug, etc
3942
_settingsHTML: $("<div id='msu-settings-dialog' title='MegaScratchUserscript Settings'></div>"),
4043
_partsEnabled: {},
4144
_init: function(){
@@ -55,7 +58,7 @@ var ScratchUserscript = {
5558
ScratchUserscript._settingsHTML.css("display","none").appendTo(document.body).dialog({dialogClass:"jqui-modal", autoOpen: false, width: 800, height: 550});
5659
$("#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>');
5760
ScratchUserscript._settingsHTML.html(GM_getResourceText("settingshtml"));
58-
GM_addStyle(GM_getResourceText("settingscss"));
61+
GM_addStyle(GM_getResourceText("settingscss2"));
5962
var openSettings = $("<a href='javascript:void(0)'><acronym title='Mega Scratch Userscript'>MSU</acronym> Settings</a>");
6063
openSettings.click(function(){
6164
ScratchUserscript._settingsHTML.dialog("open");

parts/projectStuff.part.js

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
msuParts["projectStuff"] = function (ScratchUserscript) {
2+
var settingsDlg = $("<div></div>");
3+
4+
ScratchUserscript.registerPart("Project Stuff", "Adds phosphorus and scratchblocks2 buttons to projects.", settingsDlg);
5+
6+
var settings = {
7+
phosphorus: true,
8+
sb2: true,
9+
diff: true
10+
};
11+
var labels = {
12+
phosphorus: "Enable phosphorus button",
13+
sb2: "Enable scratchblocks2 generator button",
14+
diff: "Enable scratchblocks2 diff button"
15+
};
16+
settings = ScratchUserscript.readSetting("projectStuff", "settings", settings);
17+
18+
updateChanges = function(){
19+
for(x in settings){
20+
if($("#msu-ps"+x+"btn").is(":checked")){
21+
settings[x] = true;
22+
} else {
23+
settings[x] = false;
24+
}
25+
}
26+
ScratchUserscript.writeSetting("projectStuff", "settings", settings);
27+
};
28+
29+
settingsDlg.append("<br/>");
30+
31+
for(x in settings){
32+
settingsDlg.append("<input type='checkbox' id='msu-ps"+x+"btn' /> \
33+
<label for='msu-ps"+x+"btn' \
34+
style='display: inline;margin-right:1em;'>\
35+
"+labels[x]+"</label><br/>");
36+
if(settings[x]) $("#msu-ps"+x+"btn").attr("checked", "checked");
37+
}
38+
39+
settingsDlg.find("input").bind("change", updateChanges);
40+
41+
var isEnabled = ScratchUserscript.isPartEnabled("projectStuff");
42+
43+
if (isEnabled && ScratchUserscript.getPageType().type == "project") {
44+
if(settings.phosphorus){
45+
var phosButton = $('<div id="msu-ps-phosphorus" class="action tooltip bottom isflash">'+
46+
'<span class="hovertext" id="msu-ps-phosphorus-tool"><span class="arrow"></span>Switch to phosphorus</span>'+
47+
'<span>Player type</span></div>');
48+
$(".active").append(phosButton);
49+
$("#msu-ps-phosphorus").click(function(){
50+
if($(this).hasClass('isflash')){
51+
$(this).removeClass('isflash');
52+
$(".buttons").hide();
53+
$(".player").hide();
54+
55+
var iframe = document.createElement('iframe');
56+
iframe.setAttribute('allowfullscreen', true);
57+
iframe.setAttribute('allowtransparency', true);
58+
iframe.src = 'http://phosphorus.github.io/embed.html?id=' + Scratch.INIT_DATA.PROJECT.model.id + '&auto-start=true&light-content=false';
59+
iframe.width = 482;
60+
iframe.height = 393;
61+
iframe.style.border = '0';
62+
iframe.className = 'phosphorus';
63+
var first = document.getElementsByClassName('player')[0];
64+
first.parentNode.insertBefore(iframe, first);
65+
66+
$("#msu-ps-phosphorus-tool").html("<span class='arrow'></span>Switch to flash");
67+
} else {
68+
$(this).addClass('isflash');
69+
$(".buttons").show();
70+
$(".player").show();
71+
$(".msu-phosphorus-script, .phosphorus").remove();
72+
$("#msu-ps-phosphorus-tool").htmk("<span class='arrow'></span>Switch to phosphorus");
73+
}
74+
});
75+
}
76+
if(settings.sb2){
77+
var btn = $('<div id="msu-ps-sb2" class="action tooltip bottom isflash">'+
78+
'<span class="hovertext"><span class="arrow"></span>Generate scratchblocks2 code</span>'+
79+
'<span>Generate code</span></div>');
80+
$(".active").append(btn);
81+
$("#msu-ps-sb2").click(function(){
82+
window.open('http://scratchblocks.github.io/generator/#project='+Scratch.INIT_DATA.PROJECT.model.id, "_blank");
83+
});
84+
}
85+
if(settings.diff){
86+
var btn = $('<div id="msu-ps-diff" class="action tooltip bottom isflash">'+
87+
'<span class="hovertext"><span class="arrow"></span>Generate scratchblocks2 diff</span>'+
88+
'<span>Generate diff</span></div>');
89+
$(".active").append(btn);
90+
$("#msu-ps-diff").click(function(){
91+
var diff2 = prompt("Other project ID?");
92+
if(diff2 == null || diff2 == "") return;
93+
window.open('http://scratchblocks.github.io/diff/#'+Scratch.INIT_DATA.PROJECT.model.id+"+"+diff2, "_blank");
94+
});
95+
}
96+
}
97+
};

parts/spoiler.part.js

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,34 @@
11
msuParts["spoiler"] = function (ScratchUserscript) {
2-
var settingsDlg = $("<div></div>");
2+
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>");
33

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

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

88
if (isEnabled) {
99
// actual script
1010
$(document).ready(function() {
1111
$('.postright span').each(function(index) {
12-
if($(this).attr('style')==='color:spoiler') {
13-
$('<a class="revealTag" id="openspoiler' + index + '">Open spoiler &gt;&gt;</a> ').insertBefore(this);
12+
if($(this).attr('style')==='color:spoiler' || $(this).attr('style')==='color:transparent') {
1413
var make = $(this).html();
15-
$(this).html('<span id="spoiler' + index + '">' + make + '</span>').hide();
14+
if($(this).attr('style')==='color:transparent'){
15+
$(this).css("color", "initial");
16+
}
17+
$(this).html('<blockquote><span class="bb-quote-author revealTag spoiler_closed" id="openspoiler'+index+'">'+
18+
"Open Spoiler &gt;&gt;"+
19+
'</span><div id="spoiler' + index + '" style="display:none">' + make + '</div></blockquote>');
1620
}
1721
});
1822

19-
$("a.revealTag").click(function() {
23+
$(".revealTag").css({"cursor":"pointer","text-decoration":"underline"}).click(function() {
2024
var thing = $(this).attr('id').substring(11, $(this).attr('id').length);
21-
22-
$( '#spoiler' + thing ).parent().css('display', 'inherit');
23-
24-
$(this).remove();
25+
if($(this).hasClass("spoiler_closed")){
26+
$(this).html("Close Spoiler &lt;&lt;").removeClass("spoiler_closed");
27+
$('#spoiler' + thing).slideDown();
28+
} else {
29+
$(this).html("Open Spoiler &gt;&gt;").addClass("spoiler_closed");
30+
$('#spoiler' + thing).slideUp();
31+
}
2532
});
2633
});
2734
}

resources/settings.css renamed to resources/settings2.css

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
.msu-settings-note {
66
position: absolute;
7-
bottom: 10px;
7+
bottom: 0px;
88
left: 10px;
99
}
1010

@@ -35,7 +35,7 @@
3535
border: 1px solid gray;
3636
border-bottom: none;
3737
border-right: none;
38-
padding: 10px;
38+
padding: 0.3em;
3939
margin-right: 0;
4040
margin-bottom: 0;
4141
transition: background 0.5s;

0 commit comments

Comments
 (0)