Updated firefox from 26 to 32 and part of my GM scripts failed to work. I have read https://blog.mozilla.org/addons/2014/04/10/changes-to-unsafewindow-for-the-add-on-sdk/ and few more other topics and didn't understand how to fix it. There are sample script that was good at ff26 and didn't want to run at ff32. I tried to manipulate with $/unsafeWindow and each time i got stuck at different parts. There are example that worked at ff26. Now it stuck at google.setOnLoadCallback - charts_update() didn't start. When i comment // var $ = unsafeWindow.$; then charts_update() starts ok but i will stuck after cp1. When i add unsafeWindow to google.visualization.DataTable(); after this cp1 - then cp2 is ok and i got blank visualization pane and error about denied permission. Can't understand how to fix this. :(
// ==UserScript== // @name TestScript // @namespace testing_grounds // @version 1 // @description Some description // @grant GM_getValue // @grant GM_setValue // @require http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js // ==/UserScript== //====================================================================================================================================================== // Functions //====================================================================================================================================================== function charts_update() { console.log('charts_update() started'); setInterval(charts_updateLoop, 5 * updateTimeout * 1000 / 2); } //====================================================================================================================================================== function charts_updateLoop() { console.log('charts_updateLoop() started'); $.ajax({ dataType: "json", url: '/someurl/'+'?'+Math.random(), success: function(data) { histogram_drawchart(data); }, error: null, beforeSend: null }); console.log('charts_updateLoop() finished'); } //====================================================================================================================================================== function histogram_drawchart(data) { console.log('histogram_drawchart() started'); var steps = 100; var first = data.first; var second = data.second; if (depth * 2 > first.length + second.length) depth = first.length + second.length; var lo_data = first[first.length - 1][0]; var hi_data = second[second.length - 1][0]; var max_nums = 5; var lo_data2 = lo_data.toFixed(max_nums).replace('.',''); var hi_data2 = hi_data.toFixed(max_nums).replace('.',''); var divider = (1).toPrecision(max_nums).replace('.','') * 10; var start_chart = Math.floor(lo_data2/100)*100 / divider; var end_chart = Math.ceil(hi_data2/100)*100 / divider; data_diff = (end_chart - start_chart).toFixed(max_nums - 2); var min_step = 1 / divider; var chartdata_step = (Math.max(data_diff / steps, min_step)).toFixed(max_nums); console.log('checkpoint 1'); var chartdata = new google.visualization.DataTable(); console.log('checkpoint 2'); chartdata.addColumn('number', 'Data'); chartdata.addColumn('number', 'Volume'); chartdata.addColumn('number', 'First'); chartdata.addColumn('number', 'Second'); chartdata.addRows(steps); var first_new = new Array(); var second_new = new Array(); var pos = 0; for (var i = 0; i < steps; i++) { first_new[i] = [0, 0, 0]; second_new[i] = [0, 0, 0]; } for (i = 0; i < first.length; i++) { pos = Math.floor((first[i][0] - start_chart) / chartdata_step); first_new[pos][1] = parseFloat((first_new[pos][1] + first[i][1]).toFixed(max_nums)); } var first_total = 0; for (i = steps - 1; i >=0; i--) { first_total += first_new[i][1]; first_new[i][2] = first_total; } for (i = 0; i < second.length; i++) { pos = Math.floor((second[i][0] - start_chart) / chartdata_step); second_new[pos][1] = parseFloat((second_new[pos][1] + second[i][1]).toFixed(max_nums)); } var second_total = 0; for (i = 0; i < steps; i++) { second_total += second_new[i][1]; second_new[i][2] = second_total; } for (i = 0; i < steps; i++) { pos = parseFloat((start_chart + chartdata_step * i).toFixed(max_nums)); first_vol = parseFloat((first_new[i][1]).toFixed(max_nums)); second_vol = parseFloat((second_new[i][1]).toFixed(max_nums)); full_vol = parseFloat((first_new[i][2]).toFixed(max_nums)) + parseFloat((second_new[i][2]).toFixed(max_nums)); chartdata.setValue(i, 0, pos); chartdata.setValue(i, 1, full_vol); chartdata.setValue(i, 2, first_vol); chartdata.setValue(i, 3, second_vol); } console.log('checkpoint 3'); var range0 = chartdata.getColumnRange(1); console.log('checkpoint 4'); var rw0 = range0.max - range0.min; var range1_1 = chartdata.getColumnRange(2); var range1_2 = chartdata.getColumnRange(3); var rw1 = range1_2.max - range1_1.min; if (!chart_one) { $('#chart_div').after( $('<div id="chart_histogram">') ); $('#histogram').css('height', '400px'); chart_one = new google.visualization.ComboChart(document.getElementById('chart_histogram')); } console.log('checkpoint 5'); chart_one.draw( chartdata, { width: '100%', height: 400, title: $('Distribution Chart of some params').text().replace(/:$/, ''), chartArea:{ left: 54, top: 20, width: 690, }, bar: {groupWidth: '100%'}, isStacked: false, series: { 0 : {type: "line", color: "#00ff00" }, 1 : {type: "bars", targetAxisIndex: 1, color: "#0000ff" }, 2 : {type: "bars", targetAxisIndex: 1, color: "#ff0000" } }, vAxes: [ { viewWindowMode: 'maximum' ,viewWindow: { min: range0.min - 0.2 * rw0, max: range0.max + 0.2 * rw0 } ,gridlines: { count: 5, color: '#abcdef' } }, { viewWindowMode: 'maximum' ,viewWindow: { min: range1_1.min - 0.2 * rw1, max: range1_2.max + 0.2 * rw1 } ,gridlines: { count: 4, color: '#fedcba' } } ] } ); } //====================================================================================================================================================== //====================================================================================================================================================== // Main code //====================================================================================================================================================== console.log('unsafeWindow: ' + unsafeWindow); var $ = unsafeWindow.$; console.log('$: ' + $); var chart_one = null; var google = unsafeWindow.google; console.log('google: ' + google); var updateTimeout = 5; google.setOnLoadCallback(charts_update); $(document).ready( function (){ alert('document ready function start OK'); var testscript_charts_counter = GM_getValue('testscript_charts_counter', 0); console.log('"Test script charts" started ' + testscript_charts_counter + ' times.'); GM_setValue('testscript_charts_counter', ++testscript_charts_counter); } ); -- You received this message because you are subscribed to the Google Groups "greasemonkey-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/greasemonkey-users. For more options, visit https://groups.google.com/d/optout.
