是否可以计算这个bookmarklet被点击了多少次,如果可以,如何得到一个文件的点击次数

Is it possible to count how many times this bookmarklet is clicked and if so, how to get the number of clicks in to a file?

本文关键字:一个 文件 何得 bookmarklet 计算 如果可以 是否 多少次      更新时间:2023-09-26

我有一个javascript代码,使用iFrames拉所需的数据。这是一个书签。我想知道是否有可能计算这个bookmarklet被点击了多少次,如果是的话,如何得到一个文件的点击次数?这是原始代码:

javascript:(function () {
if (!$('#OmniBoxDiv').length) {
    var strLoad = '<div id="OmniBoxDiv" style="display: block;background-color: gold;font-size: 1.25em;z-index: 1000;position: fixed;width: 96%;padding: 2%;  text-align: center">Loading...</div>';
    var divLoad = $(strLoad).prependTo('body');
}
if(typeof OmniBox === 'object'){
    OmniBox.msg();
    return;
}
OmniBox = this;
var FStatus = $('tr:has(td:contains("FStatus")):eq(1)>td:eq(1)').text();
var MStatus = $('tr:has(td:contains("MStatus")):eq(2)>td:eq(1)').text();
var Flink = $('a:contains("F Profile")').attr('href');
    this.msg = function(){
            '<tr><td></td><td>Fstatus:</td><td>'+FStatus+'</td></tr>'+
        '<tr><td>IGC</td><td></td><td></td></tr>'
        str = '<table>' + str + '</table><a href="javascript:OmniBox.CloseOmniBox();" style="background-color: darkorange;display: inline-block;padding: 0.5% 1%;cursor: pointer;">Close</a>';
        $('#OmniBoxDiv').html(str);
    }
};
this.CloseOmniBox = function(){
    $('#OmniBoxDiv').remove();
};
var FCheck = false, MCheck = false; 
var IFF = $('<iframe>'), IFM = $('<iframe>');
$('body').append(IFF);$('body').append(IFM);$('body');
IFF.attr('id','IFF').css('display','none').attr('src',FLink).on('load',function(){
    "code"
    },
    function(){
        FCheck = true;
        msg();
    });
});
"code"
    },
    function(){
        MCheck = true;
        msg();
    });
});

});
function whilst (condition, action, final) {
    var handle = setInterval(function () {
        if (condition()) {
            action();
        } else {
            clearInterval(handle);
            final();
        }
    }, 500);
}
})();

您可以按以下方式计算页面上的点击次数。但是,请记住,当您离开该页面时,您将丢失该计数,除非您使用cookie来持久保存计数。

//cache count display element
var cClick = $('#click_count');
//set up click event handler for the page
$(document).on('click', function() {
    
    //retrieve, increment, store and display click count
    cClick.text( ++cClick.data()['count'] );
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
Click Count: 
<span id="click_count" data-count="0">0</span>

可以在bookmarklet中使用全局变量

if(typeof count === number){
     count++;
} else {
     count=0;
}

您可以为该变量选择更具体的名称,以避免当前页面上的冲突。如果你想

,你也可以使用localStorage来保存计数