"Uncaught SyntaxError: Unexpected end of input" When converting to bookmarklet

"Uncaught SyntaxError: Unexpected end of input" When converting to bookmarklet

我有一个脚本可以像普通 JS 一样正常工作,但是当我使用 https://mrcoles.com/bookmarklet/ 将其转换为小书签并尝试 运行 它时,我得到 Uncaught SyntaxError: Unexpected end of input

我以前用这个网站转换成小书签没有任何错误。如果我将未转换的代码粘贴到控制台并调用该函数 运行 没问题。

未转换:

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;
}

这里是转换过来的。

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)()

已将评论从 //

更新为 /**/

我认为转换是将其作为一条长评论捕捉到,这解决了它。

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);
}