|
| 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 | +}; |
0 commit comments