使我的书签跨浏览器

发布于 2024-10-19 19:44:54 字数 1354 浏览 4 评论 0原文

这是我之前与此问题相关的问题: 阅读源代码来自 IE/Chrome/Firefox 中选项卡的代码

我不太擅长 JavaScript。我能够编写一些可以在 Firefox 中运行但不能在 IE 或 Chrome 中运行的东西。有人可以帮我让它在 IE、Firefox 和 Chrome 下运行吗?我正在运行 IE 8、Firefox 3.6.13 和 Chrome 6。

我的总体计划是进入显示密码的页面,突出显示密码,单击书签工具栏上的书签按钮,正确的解码密码将出现在屏幕上的文本框。

javascript:(
    function()
    {
        var selectedText = document.getSelection();
        if (selectedText == "")
        {
            alert('Please select the pass code before clicking the button.');
            return;
        }

        var map = [];
        map["0"] = "Z";
        map["1"] = "D";
        map["2"] = "H";
        map["3"] = "K";
        map["4"] = "N";
        map["5"] = "E";
        map["6"] = "H";
        map["7"] = "S";
        map["8"] = "U";
        map["9"] = "W";
        map["A"] = "M";
        map["B"] = "Q";
        map["C"] = "H";
        map["D"] = "A";
        map["E"] = "P";
        map["F"] = "O";
        var output = "";  

        for (var i = 0; i < selectedText.length; i++)
        {
            output = output + map[selectedText[i]];  
        }

        var frmObject = document.forms[0]; 
        var frmElement = frmObject.elements["txtPassCode"]; 
        frmElement.value = output; 
    }
)();

Here is my previous question that is related to this question: Read source code from tabs in IE/Chrome/Firefox.

I'm not very good at Javascript. I was able to write something that works in Firefox but not in IE or Chrome. Can someone help me get this running under IE, Firefox and Chrome? I am running IE 8, Firefox 3.6.13 and Chrome 6.

My general plan is to get to the page where the passcode is presented, highlight the pass code, click the bookmarklet button on my bookmarks toolbar and the correct decoded passkey will appear in the textbox on the screen.

javascript:(
    function()
    {
        var selectedText = document.getSelection();
        if (selectedText == "")
        {
            alert('Please select the pass code before clicking the button.');
            return;
        }

        var map = [];
        map["0"] = "Z";
        map["1"] = "D";
        map["2"] = "H";
        map["3"] = "K";
        map["4"] = "N";
        map["5"] = "E";
        map["6"] = "H";
        map["7"] = "S";
        map["8"] = "U";
        map["9"] = "W";
        map["A"] = "M";
        map["B"] = "Q";
        map["C"] = "H";
        map["D"] = "A";
        map["E"] = "P";
        map["F"] = "O";
        var output = "";  

        for (var i = 0; i < selectedText.length; i++)
        {
            output = output + map[selectedText[i]];  
        }

        var frmObject = document.forms[0]; 
        var frmElement = frmObject.elements["txtPassCode"]; 
        frmElement.value = output; 
    }
)();

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

宁愿没拥抱 2024-10-26 19:44:54
<script type="text/javascript">
    function GetSelectedText () {
        if (window.getSelection) {        // Firefox, Opera, Google Chrome and Safari
            var range = window.getSelection ();                                        
            alert (range.toString ());
        } 
        else {
            if (document.selection.createRange) {        // Internet Explorer
                var range = document.selection.createRange ();
                alert (range.text);
            }
        }
    }
</script>

来源:http://help.dottoro.com/ljcvonpc.php

<script type="text/javascript">
    function GetSelectedText () {
        if (window.getSelection) {        // Firefox, Opera, Google Chrome and Safari
            var range = window.getSelection ();                                        
            alert (range.toString ());
        } 
        else {
            if (document.selection.createRange) {        // Internet Explorer
                var range = document.selection.createRange ();
                alert (range.text);
            }
        }
    }
</script>

source : http://help.dottoro.com/ljcvonpc.php

っ〆星空下的拥抱 2024-10-26 19:44:54

尝试将代码长度优化到 500 个字符以下,目前超过 900 个字符。

Try to optimize your code length to under 500 character, current it's more then 900.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文