Reputation: 167
I have a script that works fine just as plain JS, but when I use https://mrcoles.com/bookmarklet/ to convert it to a bookmarklet and try to run it I get Uncaught SyntaxError: Unexpected end of input
I have used this website before to convert to Bookmarklets without any errors. If I paste the un-converted code into the console and call the function it runs fine.
un-converted:
function copy() {
var number = document.getElementById('sys_readonly.rm_story.number').value,
shortDescription = document.getElementById('rm_story.short_description').value,
d = new Date(),
year = d.getFullYear(),
//The '0' and slice makes sure the numbers are at least 2 characters long. The '+1' is becuase it starts at January == 0.
month = ('0' + (d.getMonth() + 1)).slice(-2),
day = ('0' + d.getDate()).slice(-2),
name = (year) + (month) + (day) + ' - ' + number + ' - ' + shortDescription;
//Cut off everything past 80 characters
if(name.length > 80) name = name.substring(0,80);
// Pushes the String into the "Update Sets" field
document.getElementById('rm_story.u_update_set').value = name;
}
Here it is converted.
javascript:(function()%7Bfunction%20copy()%20%7Bvar%20number%20%3D%20document.getElementById('sys_readonly.rm_story.number').value%2CshortDescription%20%3D%20document.getElementById('rm_story.short_description').value%2Cd%20%3D%20new%20Date()%2Cyear%20%3D%20d.getFullYear()%2C%2F%2FThe%20'0'%20and%20slice%20makes%20sure%20the%20numbers%20are%20at%20least%202%20characters%20long.%20The%20'%2B1'%20is%20becuase%20it%20starts%20at%20January%20%3D%3D%200.month%20%3D%20('0'%20%2B%20(d.getMonth()%20%2B%201)).slice(-2)%2Cday%20%3D%20('0'%20%2B%20d.getDate()).slice(-2)%2Cname%20%3D%20(year)%20%2B%20(month)%20%2B%20(day)%20%2B%20'%20-%20'%20%2B%20number%20%2B%20'%20-%20'%20%2B%20shortDescription%3B%2F%2FCut%20off%20everything%20past%2080%20charactersif(name.length%20%3E%2080)%20name%20%3D%20name.substring(0%2C80)%3B%2F%2F%20Pushes%20the%20String%20into%20the%20%22Update%20Sets%22%20fielddocument.getElementById('rm_story.u_update_set').value%20%3D%20name%3B%7D%7D)()
Upvotes: 3
Views: 1907
Reputation: 167
Updated the comments to /**/
from //
I think the conversion was catching it as one long comment and this solved it.
function copy() {
var number = document.getElementById('sys_readonly.rm_story.number').value,
shortDescription = document.getElementById('rm_story.short_description').value,
d = new Date(),
year = d.getFullYear(),
/*The '0' and slice makes sure the numbers are at least 2 characters long. The '+1' is becuase it starts at January == 0.*/
month = ('0' + (d.getMonth() + 1)).slice(-2),
day = ('0' + d.getDate()).slice(-2),
name = (year) + (month) + (day) + ' - ' + number + ' - ' + shortDescription;
/*Cut off everything past 80 characters*/
if(name.length > 80) name = name.substring(0,80);
/*Pushes the String into the "Update Sets" field*/
document.getElementById('rm_story.u_update_set').value = name;
console.log(name);
}
Upvotes: 11