Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow silent Save Page Now to save to My Web Archive #1026

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions webextension/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,10 @@
<span class="auth-icon"><input type="checkbox" class="saved-setting clear-on-logout" id="my-archive-setting"></span>
<div class="setting-text-box">
<span class="toggle auth-dim">Save To My Web Archive</span>
<div style="margin-top: 0.5em; line-height: 1em">
<input type="checkbox" class="saved-setting clear-on-logout" id="auto-my-archive-setting">
<label for="auto-my-archive-setting" id="auto-my-archive-label" style="margin-top: 5px; font-size: 11px;">always save</label>
</div>
</div>
</label>
<label class="setting-switch" for="resource-list-setting">
Expand Down
20 changes: 12 additions & 8 deletions webextension/scripts/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,10 +208,12 @@ function statusSuccess(atab, pageUrl, silent, data) {
url: pageUrl
}, checkLastError)

if (!data || !('timestamp' in data)) return

checkSaveToMyWebArchive(pageUrl, data.timestamp, silent)

// notify
if (!silent && data && ('timestamp' in data)) {
// since not silent, saves to My Web Archive only if SPN explicitly clicked and turned on
checkSaveToMyWebArchive(pageUrl, data.timestamp)
if (!silent) {
// replace message if present in result
let msg = 'Successfully saved! Click to view snapshot.'
if (('message' in data) && (data.message.length > 0)) {
Expand Down Expand Up @@ -518,10 +520,13 @@ function checkNotFound(details) {
}

// Calls saveToMyWebArchive() if setting is set, and outputs errors to console.
//
function checkSaveToMyWebArchive(url, timestamp) {
chrome.storage.local.get(['my_archive_setting'], (settings) => {
if (settings && settings.my_archive_setting) {
// silent is false if triggered by SPN, true otherwise
function checkSaveToMyWebArchive(url, timestamp, silent) {
chrome.storage.local.get(['my_archive_setting', 'auto_my_archive_setting'], (settings) => {
if (!settings || !settings.my_archive_setting) { return }
// save if not triggered by SPN and always save setting is enabled
if (!settings.auto_my_archive_setting && silent) { return }

saveToMyWebArchive(url, timestamp)
.then(response => response.json())
.then(data => {
Expand All @@ -532,7 +537,6 @@ function checkSaveToMyWebArchive(url, timestamp) {
.catch(error => {
console.log('Save to My Web Archive FAILED: ', error)
})
}
})
}

Expand Down
26 changes: 24 additions & 2 deletions webextension/scripts/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
/* global setupWaybackCount, goBackToMain */

// onload
$(function() {
$(function () {
initSettings()
setupPrivateMode()
setupSettingsChange()
Expand Down Expand Up @@ -35,6 +35,7 @@ function restoreSettings(items) {
$('#tvnews-setting').prop('checked', items.tvnews_setting)
// second panel
$('#auto-archive-setting').prop('checked', items.auto_archive_setting)
$('#auto-my-archive-setting').prop('checked', items.auto_my_archive_setting)
$('#auto-archive-age').val(items.auto_archive_age || '99999')
$('#auto-bookmark-setting').prop('checked', items.auto_bookmark_setting)
$('#email-outlinks-setting').prop('checked', items.email_outlinks_setting)
Expand All @@ -45,6 +46,7 @@ function restoreSettings(items) {
$(`input[name=view-setting-input][value=${items.view_setting}]`).prop('checked', true)
// update UI
enableEmbedPopupSetting(items.not_found_setting)
enableAutoMyArchiveSetting(items.auto_archive_setting)
}

function saveSettings() {
Expand All @@ -62,6 +64,7 @@ function saveSettings() {
tvnews_setting: $('#tvnews-setting').prop('checked'),
// second panel
auto_archive_setting: $('#auto-archive-setting').prop('checked'),
auto_my_archive_setting: $('#auto-my-archive-setting').prop('checked'),
auto_archive_age: $('#auto-archive-age').val(),
auto_bookmark_setting: $('#auto-bookmark-setting').prop('checked'),
email_outlinks_setting: $('#email-outlinks-setting').prop('checked'),
Expand Down Expand Up @@ -111,6 +114,17 @@ function enableEmbedPopupSetting(flag) {
}
}

// Enable or disable setting when flag is true or false.
function enableAutoMyArchiveSetting(flag) {
if (flag) {
$('#auto-my-archive-setting').attr('disabled', false)
$('#auto-my-archive-label').css('opacity', '1.0').css('cursor', '')
} else {
$('#auto-my-archive-setting').attr('disabled', true)
$('#auto-my-archive-label').css('opacity', '0.66').css('cursor', 'not-allowed')
}
}

// Save settings on change and other actions on particular settings.
function setupSettingsChange() {

Expand All @@ -122,6 +136,14 @@ function setupSettingsChange() {
$('#auto-archive-setting').prop('checked', true).trigger('change')
e.target.blur()
})
$('#my-archive-setting').change((e) => {
enableAutoMyArchiveSetting($(e.target).prop('checked') === true)

if ($(e.target).prop('checked') === false) {
$('#auto-my-archive-setting').prop('checked', false).trigger('change')
e.target.blur()
}
})

// auto save bookmarks
if (isSafari) {
Expand Down Expand Up @@ -242,7 +264,7 @@ function setupHelpDocs() {
'auto-archive-setting': 'Archive URLs that have not previously been archived to the Wayback Machine.',
'auto-bookmark-setting': 'Archive when bookmarking a website, except Excluded URLs.',
'email-outlinks-setting': 'Send an email of results when Outlinks option is selected.',
'my-archive-setting': 'Adds URL to My Web Archive when Save Page Now is selected.',
'my-archive-setting': 'Adds URL to My Web Archive only when Save Page Now is triggered (unless "always save" is turned on).',
'notify-setting': 'Turn off all notifications.',
'resource-list-setting': 'Display embedded URLs archived with Save Page Now.'
}
Expand Down