修改书签以使用剪贴板中的相同副本处理剪贴板内容和填写表单 [英] Revise bookmarklet to use the same copy from clipboard to process the clipboard contents and fill form

查看:382
本文介绍了修改书签以使用剪贴板中的相同副本处理剪贴板内容和填写表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现两个书签可以从剪贴板获取格式化的文本,并在另一个页面上填写表单。这甚至工作跨域和跨浏览器。问题是书签B不能填充与A可以相同的形式。



留下书签A的唯一的真正的问题是它有一个粘贴



好的页面来测试这些bookmarlets:google.com/advanced_search

/ p>

BookmarkletA资料来源: http://wundes.com /bookmarklets.html (BTW它在IE中工作,尽管页面上说不会。)



javascript:function% 20repop(){var%20j,A =,D,E,F = document.forms,G =,div =〜::〜,H,FA = [] = [],DA = []; H = prompt(Paste-Form-Vars-Here,); K = H.split(〜jdiv〜); while(K.length> 0){var %20L = K.shift()。split(div); mypush(L,FA);} var%20alen = FA.length; for(var%20c = 0; c



它希望的剪贴板内容需要看起来像:
0〜::〜text〜::〜jdiv〜0〜::〜text〜::〜as_eq〜::〜你看到这个bookmarklet工作了!〜jdiv〜



BookmarkletB资料来源: https://github.com/cvuorinen/my-bookmarklets/tree/master/form-populate



javascript:(function(){t =''; c = window.clipboardData; if(c){t = c.getData('Text') ;} if(!t){t = window.prompt('Paste:');} p = t.split('|'); t = p.shift(); t = t.split(';') ; v = t [0] .split(':'); f = t [1] .split(':'); l = v.length; d =((f.length> l + 1) '+ f [1 + 1] +'。':'')+'document。'+ f [1] +' [i])。value = v [i];} p = p.join('|'); if(c){c.setData('Text',p);} else if(p){window.prompt ('Copy:',p);}})();



剪贴板内容需要看起来像: p>

如果您看到此书签工作正常!; as_eq:f



我真的不知道javascript,我花了50多个小时试图研究一种方式来传输表单数据跨域没有网络服务器。



足够让我的page1(这是在我的控制生成剪贴板)发布已使第二页尽可能容易使用。



我真的认为这是可能的做,但不知道如何修改bookmarletA像B一样,从剪贴板复制。如果我必须与A一起生活,我会确定,但我的最终解决方案将是如此好多,如果我可以避免ctrl-v步骤,并使它成为一个双击解决方案。



感谢您提供任何帮助。



更新:4/14/16使用IE开发工具后,我发现了罪魁祸首。它与t变量有关。



'javascript:function%20repop(){var%20j,A =,t,D,E,F = document.forms,G = div =〜::〜,H,FA = [],TA = [],DF = [],DA = [],c;%20%20c = window.clipboardData;%20%20if%20 )%20 {%20%20%20%20H = c.getData('Text');} K = H.split(〜jdiv〜); while(K.length> 0){var%20L = K .shift()。split(div); mypush(L,FA);} var%20alen = FA.length; for(var%20c = 0; c

因为你已经在原始副本书签的格式已经在剪贴板上的形式内容(更多的在上面提到的书签A源),那么这个修订的书签将填充它。

解决方案

原来的bookmarklet开发者提供了下面的..似乎它只适用于某些IE版本希望这有助于某人需要这个表单填充功能。



javascript:function%20repop(){var%20j,A =,D,E,F = document.forms,G =,div =〜 ::〜,H,FA = [],TA = [],DF = [],DA = [],c;%20%20c = window.clipboardData; wait(3000);%20% c)%20 {%20%20%20%20%20%20%20%20%20%20%20%20%20%20% 20%20%20H = window.prompt('Paste:');%20%20} K = H.split(〜jdiv〜); while(K.length> 0){var%20L = (a)(a)(c)(c)(c)(c)(c)(c)(c)(c) (var%20eff%20in%20TA){for(var%20eff%20in%20TA)} {} %20in%20TA [eff]){for(var%20i%20in%20TA [eff] [o] .objArr){var%20fl = F [eff] ; df ++){var%20dff = F [eff] [df]; var%20taf = TA [eff] [o] .objArr [i]; if(dff.name == taf [1] 2] .length == 0 || taf [2] .length == undefined){taf [2] =;} dff.value = taf [2];}}}}}} repop null); function%20addObj(obj,ElArr){for(i%20in%20obj){for(var%20e%20in%20ElArr){if(obj [i] [0] == ElArr [e] .name) {ElArr [e] .objArr.push(obj [i]); break;}}}} function%20mypush(a,Ar){var%20n = a.shift(); if(Ar [n] == undefined ){Ar [n] = [];} Ar [n] .push(a);} function%20addtypes(a,Ar){for(var%20e%20in%20a){var%20t = a [e] [0]; if(elemIndexOf(t,Ar)== - 1){var%20bob = new%20Elemental(t,[]); Ar.push(bob);}}} function%20elemIndexOf(s,a) {var%20ln = a.length; for(var%20x = 0; x< ln; x ++){if(a [x] .name == s){return(x);}} return } function%20Elemental(name,objArr){this.name = name; this.objArr = objArr;}


I have found two bookmarlets that can take formatted text from the clipboard and fill a form on another page. This works even cross domain and cross browsers. The problem is that bookmarklet "B" cannot fill the same form that "A" can.

Leaving the only real problem with bookmarklet "A" being that it has a paste the clipboard inbox that bookmarklet "B" doesn't have to show but falls back on if necessary.

Good page to test these bookmarlets on: google.com/advanced_search

Bookmarklet "A" Source: http://wundes.com/bookmarklets.html (BTW it does work in IE despite the page saying it won't.)

javascript:function%20repop(){var%20j,A="",D,E,F=document.forms,G="",div="~::~",H,FA=[],TA=[],DF=[],DA=[];H=prompt("Paste-Form-Vars-Here","");K=H.split("~jdiv~");while(K.length>0){var%20L=K.shift().split(div);mypush(L,FA);}var%20alen=FA.length;for(var%20c=0;c<alen;c++){TA[c]=[];addtypes(FA[c],TA[c]);}for(all%20in%20FA){addObj(FA[all],TA[all]);}for(var%20eff%20in%20TA){for(var%20o%20in%20TA[eff]){for(var%20i%20in%20TA[eff][o].objArr){var%20fl=F[eff].length;for(var%20df=0;df<fl;df++){var%20dff=F[eff][df];var%20taf=TA[eff][o].objArr[i];if(dff.name==taf[1]){if(taf[2].length==0||taf[2].length==undefined){taf[2]="";}dff.value=taf[2];}}}}}}repop();void(null);function%20addObj(obj,ElArr){for(i%20in%20obj){for(var%20e%20in%20ElArr){if(obj[i][0]==ElArr[e].name){ElArr[e].objArr.push(obj[i]);break;}}}}function%20mypush(a,Ar){var%20n=a.shift();if(Ar[n]==undefined){Ar[n]=[];}Ar[n].push(a);}function%20addtypes(a,Ar){for(var%20e%20in%20a){var%20t=a[e][0];if(elemIndexOf(t,Ar)==-1){var%20bob=new%20Elemental(t,[]);Ar.push(bob);}}}function%20elemIndexOf(s,a){var%20ln=a.length;for(var%20x=0;x<ln;x++){if(a[x].name==s){return(x);}}return(-1);}function%20Elemental(name,objArr){this.name=name;this.objArr=objArr;}

The clipboard content it is expecting needs to look like: 0~::~text~::~jdiv~0~::~text~::~as_eq~::~If you see this the bookmarklet worked!~jdiv~

Bookmarklet "B" Source: https://github.com/cvuorinen/my-bookmarklets/tree/master/form-populate

javascript:(function(){t='';c=window.clipboardData;if(c){t=c.getData('Text');}if(!t){t=window.prompt('Paste:');}p=t.split('|');t=p.shift();t=t.split(';');v=t[0].split(':');f=t[1].split(':');l=v.length;d=((f.length>l+1)?'window.'+f[l+1]+'.':'')+'document.'+f[l]+'.';for(i=0;i<l;i++){eval(d+f[i]).value=v[i];}p=p.join('|');if(c){c.setData('Text',p);}else if(p){window.prompt('Copy:',p);}})();

The clipboard content it is expecting needs to look like:

If you see this the bookmarklet worked!;as_eq:f

I honestly don't know javascript and I have spent well over 50 hours trying to research a way to transfer form data cross domain without a webserver.

Its easy enough to make my page1 (that is in my control generate the clipboard) Issue has been making the 2nd page as easy as possible to use.

I really think this is possible to do but not sure how to modify bookmarlet "A" to act like "B" does with the copy from clipboard. If I have to live with "A" I will be ok but my final solution will be so much better if I can avoid the ctrl-v step and make it a two click solution.

Thanks in advance for any assistance.

Update: 4/14/16 after using IE developer tools I found the culprit. It had something to do with the t variable.

'javascript:function%20repop(){var%20j,A="",t,D,E,F=document.forms,G="",div="~::~",H,FA=[],TA=[],DF=[],DA=[],c;%20%20c=window.clipboardData;%20%20if%20(c)%20{%20%20%20%20H=c.getData('Text');}K=H.split("~jdiv~");while(K.length>0){var%20L=K.shift().split(div);mypush(L,FA);}var%20alen=FA.length;for(var%20c=0;c

This bookmarklet as long as you have the form content already on the clipboard in the format that the original copy bookmarklet makes (see more at the bookmarklet A source previously mentioned) then this revised bookmarklet will fill it in.

解决方案

The original bookmarklet developer provided the following.. Seems it only works in some IE versions. Hope this helps someone that needs this form filling functionality.

javascript:function%20repop(){var%20j,A="",D,E,F=document.forms,G="",div="~::~",H,FA=[],TA=[],DF=[],DA=[],c;%20%20c=window.clipboardData;wait(3000);%20%20if%20(c)%20{%20%20%20%20H=c.getData('Text');%20%20}%20%20%20%20if%20(!t)%20%20{%20%20%20%20H=window.prompt('Paste:');%20%20}K=H.split("~jdiv~");while(K.length>0){var%20L=K.shift().split(div);mypush(L,FA);}var%20alen=FA.length;for(var%20c=0;c<alen;c++){TA[c]=[];addtypes(FA[c],TA[c]);}for(all%20in%20FA){addObj(FA[all],TA[all]);}for(var%20eff%20in%20TA){for(var%20o%20in%20TA[eff]){for(var%20i%20in%20TA[eff][o].objArr){var%20fl=F[eff].length;for(var%20df=0;df<fl;df++){var%20dff=F[eff][df];var%20taf=TA[eff][o].objArr[i];if(dff.name==taf[1]){if(taf[2].length==0||taf[2].length==undefined){taf[2]="";}dff.value=taf[2];}}}}}}repop();void(null);function%20addObj(obj,ElArr){for(i%20in%20obj){for(var%20e%20in%20ElArr){if(obj[i][0]==ElArr[e].name){ElArr[e].objArr.push(obj[i]);break;}}}}function%20mypush(a,Ar){var%20n=a.shift();if(Ar[n]==undefined){Ar[n]=[];}Ar[n].push(a);}function%20addtypes(a,Ar){for(var%20e%20in%20a){var%20t=a[e][0];if(elemIndexOf(t,Ar)==-1){var%20bob=new%20Elemental(t,[]);Ar.push(bob);}}}function%20elemIndexOf(s,a){var%20ln=a.length;for(var%20x=0;x<ln;x++){if(a[x].name==s){return(x);}}return(-1);}function%20Elemental(name,objArr){this.name=name;this.objArr=objArr;}

这篇关于修改书签以使用剪贴板中的相同副本处理剪贴板内容和填写表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆