diff --git a/chrome_point_plus/_locales/en/messages.json b/chrome_point_plus/_locales/en/messages.json
index 8bef84c..c3ddffa 100644
--- a/chrome_point_plus/_locales/en/messages.json
+++ b/chrome_point_plus/_locales/en/messages.json
@@ -13,6 +13,9 @@
"options_text_saved": {
"message": "Reload page to apply changes."
},
+ "options_text_new_version": {
+ "message": "Point+ just updated.\nCheck your settings and try some new functions!"
+ },
"options_tabs_media": {
diff --git a/chrome_point_plus/_locales/ru/messages.json b/chrome_point_plus/_locales/ru/messages.json
index 9278359..117b315 100644
--- a/chrome_point_plus/_locales/ru/messages.json
+++ b/chrome_point_plus/_locales/ru/messages.json
@@ -13,6 +13,9 @@
"options_text_saved": {
"message": "Для применения изменений перезагрузите страницу."
},
+ "options_text_new_version": {
+ "message": "Point+ только что обновился.\nПроверьте настройки и оцените новые функции!"
+ },
"options_tabs_media": {
diff --git a/chrome_point_plus/css/point-plus.css b/chrome_point_plus/css/point-plus.css
index 5957d16..e71bd12 100644
--- a/chrome_point_plus/css/point-plus.css
+++ b/chrome_point_plus/css/point-plus.css
@@ -213,14 +213,6 @@ div#markItUpText-input {
-webkit-filter: blur(30px);
}
-/* point-plus-debug */
-.point-plus-debug{
- float: right;
- display: block;
- color: rgba(255,255,255,.75);
- padding: 10px 0px;
-}
-
.post-tag-nsfw.hide-nsfw-posts,
.post-tag-сиськи.hide-nsfw-posts{
display: none;
@@ -237,11 +229,10 @@ div#markItUpText-input {
color: green;
}
-
-
-
-
-
-
-
-
+/* point-plus-debug */
+#point-plus-debug{
+ float: right;
+ display: block;
+ color: rgba(255,255,255,.75);
+ padding: 10px 0px;
+}
\ No newline at end of file
diff --git a/chrome_point_plus/js/background.js b/chrome_point_plus/js/background.js
index 3fcce1a..6acddc7 100644
--- a/chrome_point_plus/js/background.js
+++ b/chrome_point_plus/js/background.js
@@ -1,3 +1,13 @@
+// Maintaining options version
+chrome.storage.sync.get('options_version', function(data) {
+ var pp_version = getVersion();
+ console.info('Point+ %s. Options are for %s.', pp_version, data.options_version);
+
+ if (data.options_version != pp_version) {
+ chrome.tabs.create({url: 'options.html'});
+ }
+});
+
// Message listener
chrome.extension.onMessage.addListener(function(message, sender) {
console.log('Received message: %O', message);
@@ -69,4 +79,13 @@ chrome.extension.onMessage.addListener(function(message, sender) {
break;
}
}
-});
\ No newline at end of file
+});
+
+// Getting version from manifest.json
+function getVersion() {
+ var xhr = new XMLHttpRequest();
+ xhr.open('GET', chrome.extension.getURL('manifest.json'), false);
+ xhr.send(null);
+ var manifest = JSON.parse(xhr.responseText);
+ return manifest.version;
+}
\ No newline at end of file
diff --git a/chrome_point_plus/js/options.js b/chrome_point_plus/js/options.js
index 26544fe..da6464c 100644
--- a/chrome_point_plus/js/options.js
+++ b/chrome_point_plus/js/options.js
@@ -1,37 +1,62 @@
var ppOptions = {};
-// Initializing full options structure
-// Saves options to localStorage.
-function pp_init_options() {
- $('.option-node').find('input').each(function(idx, $input) {
- console.log($(this));
-
- // Using option types
- if ($(this).hasClass('option-boolean')) {
- ppOptions[$(this).prop('id').replace(/-/g, '_')] = {
- 'type': 'boolean',
- 'value': $(this).prop('checked')
- };
- } else if ($(this).hasClass('option-enum')) {
- if ($(this).prop('checked')) {
- ppOptions[$(this).prop('name').replace(/-/g, '_')] = {
- 'type': 'enum',
- 'value': $(this).val()
- }
- }
- }
- });
+// Binding event listeners
+$(function() {
+ pp_restore_options();
- console.log('Saving options: %O', ppOptions);
+ // Delegating events
+ $('#tabs-content').on('click', 'input', function() {
+ pp_save_options();
+ });
+});
- // Saving parameters
- chrome.storage.sync.set({'options': ppOptions}, function() {
- console.log('Default options initialized');
+// Initializing full options structure
+function pp_init_options() {
+ var pp_version = getVersion();
+
+ chrome.storage.sync.get('options_version', function(data) {
+ console.info('Point+ %s, local options are for %s', pp_version, data.options_version);
+
+ // Checking last options version
+ if (data.options_version != getVersion()) {
+ console.log('Initializing options...');
+
+ $('.option-node').find('input').each(function(idx, $input) {
+ console.debug($(this));
+
+ // Using option types
+ if ($(this).hasClass('option-boolean')) {
+ ppOptions[$(this).prop('id').replace(/-/g, '_')] = {
+ type: 'boolean',
+ value: $(this).prop('checked')
+ };
+ } else if ($(this).hasClass('option-enum')) {
+ if ($(this).prop('checked')) {
+ ppOptions[$(this).prop('name').replace(/-/g, '_')] = {
+ type: 'enum',
+ value: $(this).val()
+ };
+ }
+ }
+ });
+
+ // Updating options
+ chrome.storage.sync.set({
+ options: ppOptions,
+ options_version: getVersion()
+ }, function() {
+ console.log('Default options initialized. Version upgraded to %s.', pp_version);
+
+ if (!confirm(chrome.i18n.getMessage('options_text_new_version'))) {
+ window.close();
+ }
+ });
+ }
});
}
-// Saves options to localStorage.
-// @todo: optimize it!
+// Saves options to sync storage.
+// @todo: optimize it! (merge)
function pp_save_options() {
$('.option-node').find('input').each(function(idx, $input) {
console.log($(this));
@@ -39,15 +64,15 @@ function pp_save_options() {
// Using option types
if ($(this).hasClass('option-boolean')) {
ppOptions[$(this).prop('id').replace(/-/g, '_')] = {
- 'type': 'boolean',
- 'value': $(this).prop('checked')
+ type: 'boolean',
+ value: $(this).prop('checked')
};
} else if ($(this).hasClass('option-enum')) {
if ($(this).prop('checked')) {
ppOptions[$(this).prop('name').replace(/-/g, '_')] = {
- 'type': 'enum',
- 'value': $(this).val()
- }
+ type: 'enum',
+ value: $(this).val()
+ };
}
}
});
@@ -55,7 +80,7 @@ function pp_save_options() {
console.log('Saving options: %O', ppOptions);
// Saving parameters
- chrome.storage.sync.set({'options': ppOptions}, function() {
+ chrome.storage.sync.set({options: ppOptions}, function() {
// Update status to let user know options were saved.
$('#status').html(chrome.i18n.getMessage('options_text_saved'));
});
@@ -65,12 +90,12 @@ function pp_save_options() {
function pp_restore_options() {
// Cleaning old style options
// Delete after some time
- chrome.storage.sync.get('option_fancybox', function(value) {
- if (value === true || value === false) {
+ chrome.storage.sync.get('option_fancybox', function(data) {
+ if ((data.option_fancybox === true) || (data.option_fancybox === false)) {
console.log('Found old-style options. Cleaning...');
- chrome.storage.sync.get(null, function(old_options) {
- console.log('Old data: %O', old_options);
- for (option in old_options) {
+ chrome.storage.sync.get(null, function(data) {
+ console.log('Old data: %O', data);
+ for (option in data) {
chrome.storage.sync.remove(option);
}
console.log('All old data removed');
@@ -78,56 +103,43 @@ function pp_restore_options() {
}
});
- // Loading options
- chrome.storage.sync.get('options', function(options) {
- // Initializing clean options
- // @todo: rewrite for all options
- if (options.option_embedding === undefined) {
- console.warn('Clean options detected. Initializing...');
- pp_init_options();
- }
-
- // Setting options in DOM
- $.each(options.options, function(key, data) {
- switch (data.type) {
- case 'boolean':
- if (data.value) {
- $('#' + key.replace(/_/g, '-')).prop('checked', true);
+ // Loading options
+ chrome.storage.sync.get('options', function(options) {
+
+ try {
+ // Setting options in DOM
+ $.each(options.options, function(key, data) {
+ switch (data.type) {
+ case 'boolean':
+ if (data.value) {
+ $('#' + key.replace(/_/g, '-')).prop('checked', true);
+ }
+ break;
+
+ case 'enum':
+ $('.option-node .option-enum[name="' + key.replace(/_/g, '-') + '"][value="' + data.value + '"]').prop('checked', true);
+ break;
+
+ default:
+ console.warn('Invalid option "%s" type: %O', key, data);
+ break;
}
- break;
-
- case 'enum':
- $('.option-node .option-enum[name="' + key.replace(/_/g, '-') + '"][value="' + data.value + '"]').prop('checked', true);
- break;
-
- default:
- console.warn('Invalid option "%s" type: %O', key, data);
- break;
+ });
+ } catch (ex) {
+ console.error('Error while loading extension options: %O', ex);
}
- });
+
// Showing version
$('#pp-version').html('Point+ ' + getVersion()
+ ' by @skobkin-ru
\n\
& @NokitaKaze'
);
- });
-
-}
-document.addEventListener('DOMContentLoaded', pp_restore_options);
-var point_plus_options_save_button = document.querySelector('#save');
-if (point_plus_options_save_button !== null) {
- point_plus_options_save_button.addEventListener('click', pp_save_options);
-}
-
-// Binding event listeners
-$(function() {
- // Delegating events
- $('#tabs-content').on('click', 'input', function() {
- pp_save_options();
+ // Initializing new options
+ pp_init_options();
});
-});
+}
// Getting version from manifest.json
function getVersion() {
diff --git a/chrome_point_plus/js/point-plus.js b/chrome_point_plus/js/point-plus.js
index 0917d26..6f20cde 100644
--- a/chrome_point_plus/js/point-plus.js
+++ b/chrome_point_plus/js/point-plus.js
@@ -1,34 +1,31 @@
+// Showing page action
+chrome.extension.sendMessage({
+ type: 'showPageAction'
+});
+
$(document).ready(function() {
// Grouping console log
console.group('point-plus');
console.info('Point+ %s', getVersion());
-
+
// Проверяем, загрузились ли мы
- // @todo: Убрать это говно и нормально пилить расширение не принося пользователям костыли
- // Хочешь детект? Делай невидимый элемент где-нибудь в подвале. И айдишник, а не класс. Их искать быстрее.
- // Хочешь показать пользователю обработку - делай индикатор и встраивай в интерфейс сайта.
- var point_plus_debug = $('.point-plus-debug');
- if (point_plus_debug.length > 0){
- console.info('Point+ already loaded, version: %s', point_plus_debug.attr('data-point-plus-version'));
+ var point_plus_debug = $('#point-plus-debug');
+ if (point_plus_debug.length > 0) {
+ console.error('Point+ %s already loaded.', point_plus_debug.data('point-plus-version'));
return;
}
- point_plus_debug = null;
- var new_div = document.createElement('div');
- $(new_div).attr({
+ $('