带有输入的javascript bookmarklet

时间:2016-07-25 19:34:25

标签: javascript bookmarklet

我正在尝试创建一个将在其中迭代值的javascript bookmarklet。

基本上我要做的就是输入类似

的内容
{
"type": "collection",
"id": "home_featured_collections_7"
},
{
"type": "collection",
"id": "home_featured_collections_8"
},
{
"type": "collection",
"id": "home_featured_collections_9"
},
{
"type": "collection",
"id": "home_featured_collections_10"
},

然后输入值如当前迭代为7,最终迭代将为10,它将输出类似

的内容
javascript:(function(){
text=prompt("Expand Text", ""); 
current=prompt("Current Iteration", ""); 
final=prompt("Final Iteration", ""); 
return_text = "";
    for (i = current; i <= final; i++) { 
        return_text += text.replace(current, i);
    } 
prompt("Copy to clipboard: Ctrl+C, Enter",return_text);}()
    );

我的第一直觉是让它从剪贴板复制原始文本,然后输出到剪贴板,但我无法弄清楚如何做到这一点。我目前正在使用提示进行设置

flatMap

但我有点麻烦。引号和冒号引起了麻烦,或者至少我认为是这种情况。这是我第一次制作js书签,所以如果有更好的方法,我会道歉。

任何建议都会很棒!

0 个答案:

没有答案