Search code examples
javascriptfirefoxtampermonkeyuserscripts

Gm_download() not work properly with name


Using tampermonkey on firefox. I have script that get url's then with for (var line in url) execute Gm_download(line, name).

var name= count + id Problem is that id variable sometime contain " / " and " : ". First one make directory instead one line name, second one (I don't know does problem from that) is broke Gm_download. How I can make Gm_download to ignore that characters or accept it like name.


Solution

  • These characters have special meaning in a file system so you can't use them in file names.

    You can replace all of them with their full-width forms so / becomes :

    name = name.replace(/[*/:<>?\\|]/g, s =>
      String.fromCharCode(s.charCodeAt(0) + 0xFF00 - 0x20));