«Uncaught SyntaxError: неожиданный конец ввода» при преобразовании в букмарклет - PullRequest
0 голосов
/ 26 июня 2018

У меня есть скрипт, который отлично работает как обычный JS, но когда я использую https://mrcoles.com/bookmarklet/, чтобы преобразовать его в букмарклет и попробовать запустить его, я получаю Uncaught SyntaxError: Unexpected end of input

Я использовал этот сайт прежде, чем конвертировать в Bookmarklets без каких-либо ошибок. Если я вставляю неконвертированный код в консоль и вызываю функцию, она работает нормально.

не преобразовано:

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

1 Ответ

0 голосов
/ 26 июня 2018

Обновлены комментарии до /**/ с //

Я думаю, что преобразование поймало это как один длинный комментарий, и это решило это.

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);
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...