This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2011-07-26 00:32:03

Sidharth
Scratcher
Registered: 2007-12-14
Posts: 100+

Experimental Viewer Bookmarklet

I made a small bookmarklet to open the experimental viewer in a different TAB, not window, because I didn't like how the link on the side opened a new window.

EDIT: The link below does not work. Use the source code to make a bookmarklet by 1) bookmarking this page, 2) renaming it to 'experimental', and 3) changing the url to what's in the code box below.

Experimental

Code:

javascript:var url = document.location.href;if (url.substr(0,32) == "http://scratch.mit.edu/projects/") {var lio = url.substring(0, url.lastIndexOf("/")).lastIndexOf("/");var part = url.substr(lio);window.open("http://scratch.mit.edu/experimental/viewproject"+part);} else {alert("I don't think this is a project page!")}

Drag and drop into bookmarks bar.

To be able to use the viewer, go here

Last edited by Sidharth (2011-07-26 00:34:15)


http://www.danasoft.com/citysign.jpg

Offline

 

#2 2011-07-26 01:02:28

JJROCKER
Scratcher
Registered: 2010-09-06
Posts: 1000+

Re: Experimental Viewer Bookmarklet

What is a bookmarklet?


http://www.blocks.scratchr.org/API.php?action=random&return=image&link1=http://img255.imageshack.us/img255/3491/signature1y.jpg&link2=http://img577.imageshack.us/img577/5272/signature1sx.jpg&link3=http://img4.imageshack.us/img4/8514/signature1et.jpg&link4=http://i.imgur.com/POEpQyZ.png&link5=http://img163.imageshack.us/img163/4640/jjrockerfinal.jpg

Offline

 

#3 2011-07-26 11:51:19

Sidharth
Scratcher
Registered: 2007-12-14
Posts: 100+

Re: Experimental Viewer Bookmarklet

JJROCKER wrote:

What is a bookmarklet?

A bookmarklet is a piece of javascript that can be saved as a bookmark so you can run it on any page. Since javascript can be written on one line, just type javascript:*your code here* and save that as the URL of a bookmark. When you click on it, your browser will execute it.


http://www.danasoft.com/citysign.jpg

Offline

 

#4 2011-07-26 11:57:52

RUMCHEERYPOOPOO
Scratcher
Registered: 2008-12-23
Posts: 100+

Re: Experimental Viewer Bookmarklet

I see what you mean, pretty cool tho

Last edited by RUMCHEERYPOOPOO (2011-07-26 11:58:10)


I AM ROOKWOOD101 NOW! (just so you know)

Offline

 

#5 2011-07-26 16:01:41

meowmeow55
Scratcher
Registered: 2008-12-24
Posts: 1000+

Re: Experimental Viewer Bookmarklet

Highlighting all the text in the code box and dragging it to the bookmark bar should work too.


Yawn.

Offline

 

#6 2011-07-27 13:04:17

horsenkat
Scratcher
Registered: 2010-09-25
Posts: 23

Re: Experimental Viewer Bookmarklet

You can also just enter it in the URL and you'll get a popup. I tried that, and it works!

Code:

<?php
function writeimageoftext($string, $subtext) {
    // Set font size
    $font_size = 2;
    $font = realpath('aller.ttf');
    // Create image width dependant on width of the string
    $width  = imagefontwidth($font_size)*strlen($string);
    // Set height to that of the font
    $height = imagefontheight($font_size);
    if (isset($subtext)) {
        $height = imagefontheight($font_size) + imagefontheight($font_size/2);
        $lensub = strlen($subtext);
    }
    // Create the image pallette
    $img = imagecreate($width,$height);
    // Grey background
    $bg    = imagecolorallocate($img, 222, 223, 223);
    // Black font color
    $color = imagecolorallocate($img, 0, 0, 0);
    // Length of the string
    $len = strlen($string);
    // Y-coordinate of character, X changes, Y is static
    $ypos = 0;
    // Loop through the string
    for($i=0;$i<$len;$i++){
        // Position of the character horizontally
        $xpos = $i * imagefontwidth($font_size);
        // Draw character
        imagechar($img, $font_size, $xpos, $ypos, $string, $color);
        // Remove character from string
        $string = substr($string, 1);
    }
    if (isset($subtext)) {
        $ypos = imagefontheight($font_size) + 1;
        $font_size = $font_size / 2;
        for($i=0;$i<$len;$i++){
            // Position of the character horizontally
            $xpos = $i * imagefontwidth($font_size);
            // Draw character
            imagechar($img, $font_size, $xpos, $ypos, $subtext, $color);
            // Remove character from string
            $subtext = substr($subtext, 1);
        }
    }
    // Return the image
    header("Content-Type: image/gif");
    imagegif($img);
    // Remove image
    imagedestroy($img);
}

$mysql_host = "*****";
$mysql_database = "*****";
$mysql_user = "*****";
$mysql_password = "*****";
$topicid = $_REQUEST['id'];
$userip = $_SERVER['REMOTE_ADDR'];

if ($_REQUEST['ret'] == 'image') {
    $topicid = $_REQUEST['id'];
    if (is_numeric($topicid) === false) {
        writeimageoftext('Error: id is not valid', '');
        exit();
    }
    $url = 'http://scratch.mit.edu/forums/viewtopic.php?id=' . $topicid;
    $urlcontents = trim(file_get_contents($url));
    if (strpos($urlcontents, 'Badrequest') != false) { //badrequest should have a space inbetween but it breaks this page otherwise.
        writeimageoftext('Error: id not found', '');
        exit();
    }
    mysql_connect($mysql_host, $mysql_user, $mysql_password) or die(mysql_error());
    mysql_select_db($mysql_database) or die(mysql_error());
    $checkquery = mysql_query("SELECT * FROM topicrate WHERE postid='$topicid'");
    if (mysql_num_rows($checkquery) == 0) {
        $likes = 0;
    }
    else {
        $topicratings = mysql_fetch_row($checkquery) or die(mysql_error());
        $ratedips = explode(',', $topicratings[1]);
        $likes = count($ratedips);
        if ($ratedips[0] == '') {
            $likes = 0;
        }
    }
    if ($likes == 1) {
        $likes = 1 . ' Like';
    }
    else {
        $likes = $likes . ' Likes';
    }
    $checkquery = mysql_query("SELECT * FROM topicrate WHERE postid='$topicid'");
    if (mysql_num_rows($checkquery) == 0) {
        $already_liked = 'Like';
    }
    else {
        $topicratings = mysql_fetch_row($checkquery) or die(mysql_error());
        $ratedips = explode(',', $topicratings[1]);
        $count = count($ratedips);
        $already_liked = 'Like';
        for($i=0; $i<$count; $i++) {
            if($ratedips[$i] == $userip) {
                $already_liked = 'Unlike';
            }
        }
    }
    writeimageoftext($likes, $already_liked);
}
elseif ($_REQUEST['ret'] == 'add') {
    $headerurl = 'Location:http://scratch.mit.edu/forums/viewtopic.php?id=' . $topicid;
    $topicid = $_REQUEST['id'];
    mysql_connect($mysql_host, $mysql_user, $mysql_password) or die(mysql_error());
    mysql_select_db($mysql_database) or die(mysql_error());
    $checkquery = mysql_query("SELECT * FROM topicrate WHERE postid='$topicid'");
    if (mysql_num_rows($checkquery) == 0) {
        $addtopic_query = mysql_query("INSERT INTO topicrate (postid, ips) VALUES ('$topicid', '$userip')");
        header($headerurl);
        exit();
    }
    else {
        $topicratings = mysql_fetch_row($checkquery) or die(mysql_error());
        $ratedips = explode(',', $topicratings[1]);
        $count = count($ratedips);
        for($i=0; $i<$count; $i++) {
            if($ratedips[$i] == $userip) {
                unset($ratedips[$i]);
                $ratedips = implode(',', $ratedips);
                $updateips_query = mysql_query("UPDATE topicrate SET ips='$ratedips' WHERE postid='$topicid'") or die(mysql_error());
                header($headerurl);
                exit();
            }
        }
        $ratedips[$count] = $userip;
        $ratedips2 = implode(',', $ratedips);
        if ($ratedips[0] == '') {
            $ratedips2 = $userip;
        }
        $updateips_query = mysql_query("UPDATE topicrate SET ips='$ratedips2' WHERE postid='$topicid'") or die(mysql_error());
        header($headerurl);
        exit();
    }
}
else {
    writeimageoftext('Error: incorrect URL vars used', 'Better luck next time!');
}
?>

It's super cool!
(He-he I changed it the tiniest bit- it now says something different)

smile


http://29.media.tumblr.com/tumblr_l8ewen1qwk1qzo7k7o1_500.gif

Offline

 

#7 2011-07-27 13:08:30

horsenkat
Scratcher
Registered: 2010-09-25
Posts: 23

Re: Experimental Viewer Bookmarklet

horsenkat wrote:

You can also just enter it in the URL and you'll get a popup. I tried that, and it works!

WRONG CODE WAS HERE

It's super cool!
(He-he I changed it the tiniest bit- it now says something different)

smile

I copied the wrong code. Nevermind. I didn't think before I posted. Sorry. Wish there was some way to delete posts...


http://29.media.tumblr.com/tumblr_l8ewen1qwk1qzo7k7o1_500.gif

Offline

 

#8 2011-07-27 17:44:18

sidharth_test
New Scratcher
Registered: 2011-07-27
Posts: 1

Re: Experimental Viewer Bookmarklet

horsenkat wrote:

horsenkat wrote:

You can also just enter it in the URL and you'll get a popup. I tried that, and it works!

WRONG CODE WAS HERE

It's super cool!
(He-he I changed it the tiniest bit- it now says something different)

smile

I copied the wrong code. Nevermind. I didn't think before I posted. Sorry. Wish there was some way to delete posts...

Yes there is: look at the bottom right corner of your post.

But I think New Scratchers can't edit posts or delete them  sad

Offline

 

#9 2011-07-27 17:45:08

Sidharth
Scratcher
Registered: 2007-12-14
Posts: 100+

Re: Experimental Viewer Bookmarklet

sidharth_test wrote:

horsenkat wrote:

horsenkat wrote:

You can also just enter it in the URL and you'll get a popup. I tried that, and it works!

WRONG CODE WAS HERE

It's super cool!
(He-he I changed it the tiniest bit- it now says something different)

smile

I copied the wrong code. Nevermind. I didn't think before I posted. Sorry. Wish there was some way to delete posts...

Yes there is: look at the bottom right corner of your post.

But I think New Scratchers can't edit posts or delete them  sad

LOL forgot to log off test acc  big_smile


http://www.danasoft.com/citysign.jpg

Offline

 

Board footer