📜 ⬆️ ⬇️

Google Chromium Extensions Development Issues

My main browser is Opera, under which the add-ons were originally developed, and then transferred to Google Chromium (build from the Ubuntu repository). I use the web version of twitter and it almost completely suits me, but it was decided to correct a few minor nuances. Then you can find out what problems got out when “porting” the extension.



First, I would like to send statuses by CTRL + ENTER. Secondly, the old style retweets (RT user_name text).
')
var pr_key = 0;
function submit_status(event) {
alert('');
}
(function () {
try {
submit_status = function (event) {
if(pr_key == 17 && event.keyCode == 13) {
$('#status_update_form').submit();
}
pr_key = event.keyCode;
}
jQuery('#status').attr('onKeyDown', 'submit_status(event);');
} catch(e) { }
})();


The first was implemented fairly quickly using JS. It was not desirable to use third-party libraries therefore it is made with small crutches. Everything worked in Opera and then it was time to build an extension for Chromium. jQuery was added to manifest.json, twi JS itself also started the tests. And immediately all the problems surfaced, as it turned out in Chromium problems with the visibility of the function definition area, onKeyDown simply did not see the submit_status () function. The problem was solved by adding a script element to the twitter code.

// ==UserScript==
// @include twitter.com*
// @include www.twitter.com*
// ==/UserScript==

(function () {

jQuery('#home').append(
'');

jQuery('#status').attr('onKeyDown', 'submit_status(event);');

})();


Above is a complete listing of the final script for Opera and Chromium. I would like to note one more thing:

'setTimeout("update_retweet();", 5000);' +


Used to call update_retweet, because from your extension also will not be able to call it.

There is another option to specify src for scripts on your (? Some code.google.com) resource, is also a way out, but it did not suit me.

Source: https://habr.com/ru/post/79479/


All Articles