Skip to content

Commit

Permalink
Merge branch 'feat/check-exists-ui-improved'
Browse files Browse the repository at this point in the history
  • Loading branch information
Simounet committed Mar 21, 2024
2 parents 7306397 + af34c08 commit 095df1d
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 6 deletions.
4 changes: 4 additions & 0 deletions wallabagger/_locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,10 @@
"message": "hour",
"description": "Options"
},
"Indicate_if_page_already_saved_into_wallabag_the_wallabagger_icon_is_green": {
"message": "Indicate if page already saved (the wallabagger icon is green)",
"description": "Options"
},
"Indicate_if_page_already_saved_this_sends_URL_of_each_tab_to_wallabag_use_HTTPS_protocol_for_better_security": {
"message": "Indicate if page already saved (this sends URL of each tab to wallabag, use HTTPS protocol for better security!)",
"description": "Options"
Expand Down
4 changes: 4 additions & 0 deletions wallabagger/_locales/fr/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,10 @@
"message": "heure",
"description": "Options"
},
"Indicate_if_page_already_saved_into_wallabag_the_wallabagger_icon_is_green": {
"message": "Indique si la page est déjà sauvegardée (l'icône de wallabagger est verte)",
"description": "Options"
},
"Indicate_if_page_already_saved_this_sends_URL_of_each_tab_to_wallabag_use_HTTPS_protocol_for_better_security": {
"message": "Indique si la page est déjà sauvegardée (tout changement d'onglet entraîne l'envoie de l'URL en cours à wallabag, utilisez le protocole HTTPS pour une meilleure sécurité !)",
"description": "Options"
Expand Down
18 changes: 18 additions & 0 deletions wallabagger/js/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ const OptionsController = function () {

this.allowSpaceCheck = document.getElementById('allow-space-checkbox');
this.allowExistCheck = document.getElementById('allow-exist-checkbox');
this.allowExistInsecureText = document.getElementById('allow-exist-insecure-text');
this.allowExistSecureText = document.getElementById('allow-exist-secure-text');
this.fetchLocallyByDefault = document.getElementById('fetch-locally-by-default-checkbox');
this.archiveByDefault = document.getElementById('archive-by-default-checkbox');
this.debugEl = document.getElementById('debug');
Expand Down Expand Up @@ -166,6 +168,7 @@ OptionsController.prototype = {
},

wallabagApiTokenGot: function () {
this.allowExistTextMessage();
this._green(this.clientId_);
this._green(this.clientSecret_);
this._green(this.userLogin_);
Expand Down Expand Up @@ -300,6 +303,7 @@ OptionsController.prototype = {

wallabagUrlChecked: function () {
if (this.data.ApiVersion) {
this.allowExistTextMessage();
this.versionLabel_.textContent = this.data.ApiVersion;
if (this.data.ApiVersion.split('.')[0] === '2') {
this._textSuccess(this.checkedLabel_);
Expand Down Expand Up @@ -445,7 +449,9 @@ OptionsController.prototype = {
}

this.allowSpaceCheck.checked = this.data.AllowSpaceInTags;

this.allowExistCheck.checked = this.data.AllowExistCheck;

this.autoAddSingleTag.checked = this.data.AutoAddSingleTag;
this.debugEl.checked = this.data.Debug;

Expand All @@ -458,6 +464,17 @@ OptionsController.prototype = {
this.sitesToFetchLocallyInputEl.value = this.data.sitesToFetchLocally;
},

allowExistTextMessage: function () {
const allowExistTextToShow = this.data.AllowExistSafe === false
? this.allowExistInsecureText
: this.allowExistSecureText;
const allowExistTextToHide = this.data.AllowExistSafe === true
? this.allowExistInsecureText
: this.allowExistSecureText;
this._hide(allowExistTextToHide);
this._show(allowExistTextToShow);
},

messageListener: function (msg) {
switch (msg.response) {
case 'setup':
Expand All @@ -475,6 +492,7 @@ OptionsController.prototype = {
case 'setup-gettoken':
Object.assign(this.data, msg.data);
if (msg.result) {
this.wallabagUrlChecked();
this.wallabagApiTokenGot();
} else {
this.wallabagApiTokenNotGot();
Expand Down
26 changes: 21 additions & 5 deletions wallabagger/js/wallabag-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ WallabagApi.prototype = {
isFetchPermissionGranted: null,
AllowSpaceInTags: false,
AllowExistCheck: false,
AllowExistSafe: null,
Debug: false,
AutoAddSingleTag: false,
ArchiveByDefault: false,
Expand All @@ -49,7 +50,10 @@ WallabagApi.prototype = {
Object.assign(this.data, this.defaultValues);
this.fetchApi = new FetchApi();
return this.load().then(
result => Promise.resolve(result)
result => {
this.setAllowExistSafe();
return Promise.resolve(result);
}
);
},

Expand Down Expand Up @@ -125,13 +129,24 @@ WallabagApi.prototype = {
CheckUrl: function () {
const url_ = this.data.Url + '/api/version';
return this.fetchApi.Get(url_, '')
.then(fetchData => { this.data.ApiVersion = fetchData; return fetchData; })
.then(fetchData => {
this.data.ApiVersion = fetchData;
this.setAllowExistSafe();
return fetchData;
})
.catch(error => {
throw new Error(`Failed to get api version ${url_}
${error.message}`);
});
},

setAllowExistSafe: async function () {
if (typeof (this.data.Url) !== 'string') {
return false;
}
this.data.AllowExistSafe = await this.SupportsHashedUrl();
},

/**
* @returns {Promise<[number, number, number]>}
*/
Expand Down Expand Up @@ -265,6 +280,7 @@ WallabagApi.prototype = {
},

GetAppToken: function (content) {
this.CheckUrl();
const oauthurl = `${this.data.Url}/oauth/v2/token`;
return this.fetchApi.Post(oauthurl, '', content)
.then(data => {
Expand Down Expand Up @@ -302,9 +318,9 @@ WallabagApi.prototype = {
EntryExists: function (url) {
const existsUrl = `${this.data.Url}/api/entries/exists.json`;

return this.CheckToken().then(() => this.SupportsHashedUrl()).then(useHashedUrl => {
const paramAsync = useHashedUrl ? hashUrl(url) : Promise.resolve(url);
return paramAsync.then(param => `${existsUrl}?${useHashedUrl ? 'hashed_url' : 'url'}=${encodeURIComponent(param)}`);
return this.CheckToken().then(() => {
const paramAsync = this.data.AllowExistSafe ? hashUrl(url) : Promise.resolve(url);
return paramAsync.then(param => `${existsUrl}?${this.data.AllowExistSafe ? 'hashed_url' : 'url'}=${encodeURIComponent(param)}`);
})
.then(url => this.fetchApi.Get(url, this.data.ApiToken))
.catch(error => {
Expand Down
4 changes: 3 additions & 1 deletion wallabagger/options.html
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,9 @@ <h3 data-i18n="Others">Others</h3>
<div class="form-group">
<label class="form-switch">
<input type="checkbox" id="allow-exist-checkbox"/>
<i class="form-icon"></i><span data-i18n="Indicate_if_page_already_saved_this_sends_URL_of_each_tab_to_wallabag_use_HTTPS_protocol_for_better_security">Indicate if page already saved (this sends URL of each tab to wallabag, use HTTPS protocol for better security!)</span>
<i class="form-icon"></i>
<span id="allow-exist-secure-text" data-i18n="Indicate_if_page_already_saved_into_wallabag_the_wallabagger_icon_is_green">Indicate if page already saved (the wallabagger icon is green)</span>
<span id="allow-exist-insecure-text" data-i18n="Indicate_if_page_already_saved_this_sends_URL_of_each_tab_to_wallabag_use_HTTPS_protocol_for_better_security">Indicate if page already saved (this sends URL of each tab to wallabag, use HTTPS protocol for better security!)</span>
</label>
</div>

Expand Down

0 comments on commit 095df1d

Please sign in to comment.