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

Fix submission to IA and View Memento UI #331

Merged
merged 1 commit into from
Jul 8, 2021
Merged
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
26 changes: 15 additions & 11 deletions mink-plugin/js/displayMinkUI.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,15 @@ function appendHTMLToShadowDOM () {
}
let mCount = mementos.length
const minkuiRoot = document.querySelector('#minkuiX')
const viewingMemento = items.timemaps && items.timemaps[document.URL] &&
items.timemaps[document.URL].mementos && items.timemaps[document.URL].datetime

if (items.timemaps && items.timemaps[document.URL] && items.timemaps[document.URL].mementos && items.timemaps[document.URL].datetime) {
if (viewingMemento) {
mCount = items.timemaps[document.URL].mementos.length

// Hide initially irrelevant UI items
const selectorsToHide = ['.dropdown', '#drildownBox', '#steps', '#title_dropdown', '#archiveNow']
const selectorsToHide = ['.dropdown', '#drilldownBox', '#steps', '#title_dropdown', '#archiveNow']

selectorsToHide.forEach(selector => {
minkuiRoot.querySelector(selector).classList.add('hidden')
})
Expand Down Expand Up @@ -107,20 +110,23 @@ function appendHTMLToShadowDOM () {
}

// Append CSS1
let mementoPlurality = 'mementos'
minkuiRoot.querySelector('#mementosAvailable span#mementoCount').innerHTML = mCount.toLocaleString()
if (mCount === 1) {
mementoPlurality = 'memento'
if (!viewingMemento) {
let mementoPlurality = 'mementos'
minkuiRoot.querySelector('#mementosAvailable span#mementoCount').innerHTML = mCount.toLocaleString()
if (mCount === 1) {
mementoPlurality = 'memento'
}
minkuiRoot.querySelector('#mementosAvailable span#mementoPlurality').innerHTML = mementoPlurality
}
minkuiRoot.querySelector('#mementosAvailable span#mementoPlurality').innerHTML = mementoPlurality

// Append CSS2
appendCSSToShadowDOM(cb)
})
})
}

const addZ = (n) => {
// In some places, getting addZ has already been declared, thus var for now
var addZ = (n) => {
return n < 10 ? '0' + n : '' + n
}

Expand Down Expand Up @@ -657,7 +663,7 @@ chrome.runtime.onMessage.addListener(
}
)

function showSuccessfullyArchivedURI (uri, openInNewTab) {
function showSuccessfullyArchivedURI (archiveURI, openInNewTab) {
chrome.runtime.sendMessage({
method: 'notify',
title: 'Mink',
Expand All @@ -666,8 +672,6 @@ function showSuccessfullyArchivedURI (uri, openInNewTab) {

const shadow = document.getElementById('minkWrapper').shadowRoot
shadow.getElementById('archivelogo_ia').classList.add('archiveNowSuccess')

const archiveURI = 'https://web.archive.org' + uri
shadow.getElementById('archivelogo_ia').setAttribute('title', archiveURI)
shadow.getElementById('archivelogo_ia').onclick = function () {
if (!openInNewTab) {
Expand Down
2 changes: 1 addition & 1 deletion mink-plugin/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"manifest_version": 2,
"name": "Mink - Integrate Live & Archived Web +Memento",
"short_name": "Mink",
"version": "2.5.1.1",
"version": "2.5.2",
"description": "Integrating the Live and Archived Web Viewing Experience Using Memento",
"homepage_url": "https://matkelly.com/mink",
"author": "Mat Kelly <mink@matkelly.com>",
Expand Down
44 changes: 23 additions & 21 deletions mink-plugin/mink.js
Original file line number Diff line number Diff line change
Expand Up @@ -220,40 +220,42 @@ chrome.runtime.onMessage.addListener(
let data = {}
let method = 'GET'
if (request.archive === 'ia') {
submissionURI = 'http://web.archive.org/save/' + request.urir
submissionURI = `http://web.archive.org/save/${request.urir}`
method = 'GET'
} else if (request.archive === 'ais') {
// TODO: get value of submitid from AIS interface
submissionURI = 'archive.is/submit/'
method = 'POST'
data = { coo: '', url: request.urir }
}

$.ajax({
method: 'GET',
url: submissionURI,
data: data
}).done(function (data, textStatus, xhr) {
chrome.tabs.query({
active: true,
currentWindow: true
}, function (tabs) {
chrome.tabs.sendMessage(tabs[0].id, {
method: 'archiveDone',
data: xhr.getResponseHeader('Content-Location'),
imgId: request.imgId,
imgURI: request.imgURI,
callback: request.cb,
newTab: request.newTab
})
})
})
window.fetch(submissionURI).then(
response => {
changeArchiveIcon(request, response)
}
)
} else {
log(`Message sent using chrome.runtime not caught: ${request.method}`)
}
}
)

function changeArchiveIcon (request, response) {
chrome.tabs.query({
active: true,
currentWindow: true
}, function (tabs) {
chrome.tabs.sendMessage(tabs[0].id, {
method: 'archiveDone',
data: response.url,
imgId: request.imgId,
imgURI: request.imgURI,
callback: request.cb,
newTab: request.newTab
})
})

}

function fetchTimeMap (uri, tabid) {
log(`Fetching TimeMap for ${uri} in tab ${tabid}`)

Expand Down