Skip to content

Commit

Permalink
Merge branch 'release/question-from-get'
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeremy committed Jun 4, 2024
2 parents 35d168c + 0348818 commit 661be9d
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 7 deletions.
12 changes: 12 additions & 0 deletions radioUpdater/assets/js/articles.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const updateArticleView = function (articleName) {

let actions = addIdByQuery('div.doi-actions', 'article-actions')

let button = document.createElement('a')
button.classList.add('btn')
button.classList.add('btn-flat')
button.style.marginRight = '2px'
button.innerText = 'Q'
button.href = '/questions/new/?article=' + articleName
actions.prepend(button)
}
2 changes: 2 additions & 0 deletions radioUpdater/assets/js/citeitright.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ function statusButton(textarea)
let status = createButton('btn-secondary')
status.classList.add('hidden')
status.style.marginLeft = '1rem'
status.style.marginTop = "1rem"
status.dataset.textarea = textarea.id
status.id = textarea.id + '_status'

Expand Down Expand Up @@ -206,6 +207,7 @@ function citeItRightButton(textarea)
let button = createButton('btn-default')
button.dataset.textarea = textarea.id
button.id = textarea.id + '_button'
button.style.marginTop = "1rem"
button.appendChild(document.createTextNode("CiteItRight (hover)"))

addCiteItRightButtonListeners(button)
Expand Down
6 changes: 4 additions & 2 deletions radioUpdater/assets/js/contentScript.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
const pathname = window.location.pathname
const articleType = pathname.split('/')[1]
const finalPart = pathname.substring(pathname.lastIndexOf('/') + 1)
const finalPart = pathname.split('/')[2]
const isEdit = finalPart === 'edit' || finalPart === 'new'

if (articleType === 'articles' && isEdit) {
if (articleType === 'articles') {
updateArticleView(finalPart)
} else if (articleType === 'articles' && isEdit) {
updateArticleEdit()
} else if (articleType === 'cases' && isEdit) {
updateCaseEdit()
Expand Down
2 changes: 1 addition & 1 deletion radioUpdater/assets/js/helperScripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const addIdByQuery = function (query, id) {
let queryResult = document.querySelector(query)
if (queryResult) {
queryResult.id = id
return queryResult
}
}

Expand All @@ -20,7 +21,6 @@ function createButton(buttonClass)
let button = document.createElement('button')
button.classList.add('btn')
button.classList.add(buttonClass)
button.style.marginTop = "1rem"

return button
}
Expand Down
31 changes: 28 additions & 3 deletions radioUpdater/assets/js/questions.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
const relatedArticlesSection = document.getElementById('mcq-related-articles')
const articleName = new URLSearchParams(window.location.search).get('article');

function updateAutoQuestion() {

// Add the form.
if (relatedArticlesSection) {
const autoQuestionDiv = document.createElement('div')
Expand Down Expand Up @@ -32,17 +34,31 @@ function updateAutoQuestion() {
questionButton.innerText = 'AutoQuestion'
questionButton.style.display = 'inline-block'
questionButton.id = 'auto-question-button'
questionButton.disabled = true

questionButton.disabled = ! articleName
questionButton.addEventListener('mouseup', getNewQuestion)

autoQuestionDiv.appendChild(questionLabel)
autoQuestionDiv.appendChild(questionDesc)

autoQuestionDiv.appendChild(questionInput)
autoQuestionDiv.appendChild(questionButton)

if (articleName) {
const preSelectedArticle = document.createElement('p')
preSelectedArticle.classList.add('help-block')
preSelectedArticle.style.color = 'purple'
preSelectedArticle.id = 'preselected-article-warning'
preSelectedArticle.innerText = "Article: " + articleName + " will be used to create the question (set in the URL ?article=).";

autoQuestionDiv.appendChild(preSelectedArticle)
}

insertAfter(relatedArticlesSection, autoQuestionDiv)

watchForArticleUpdates()

questionButton.scrollIntoView()
}
}

Expand All @@ -56,6 +72,7 @@ function watchForArticleUpdates()
if (relatedArticleList) {
let observer = new MutationObserver( function() {
document.getElementById('auto-question-button').disabled = relatedArticleList.childElementCount < 1
document.getElementById('preselected-article-warning').style.display = relatedArticleList.childElementCount < 1 ? 'block' : 'none'
})

observer.observe(relatedArticleList, { attributes: true, childList: true, attributeOldValue: true })
Expand Down Expand Up @@ -88,8 +105,16 @@ function getNewQuestion() {
questionButton.disabled = true;

// Get the first related article
let article = document.getElementsByClassName('related-article-form-li')[0].getElementsByTagName('a')[0].getAttribute("href")
article = article.substring(article.lastIndexOf('/') + 1)
let relatedArticles = document.getElementsByClassName('related-article-form-li')[0];

let article = null;
if (relatedArticles) {
article = relatedArticles.getElementsByTagName('a')[0].getAttribute("href").substring(article.lastIndexOf('/') + 1)
} else if (articleName) {
article = articleName
} else {
return
}

// Generate a prompt
let prompt = document.getElementById('auto-question-input').value
Expand Down
3 changes: 2 additions & 1 deletion radioUpdater/manifest.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "RadioUpdater",
"version": "2.0",
"version": "2.1",
"description": "Replace references on Radiopaedia.",
"manifest_version": 3,
"content_scripts": [
Expand All @@ -11,6 +11,7 @@
"all_frames": true,
"js": [
"assets/js/helperScripts.js",
"assets/js/articles.js",
"assets/js/questions.js",
"assets/js/citeitright.js",
"assets/js/contentScript.js"
Expand Down

0 comments on commit 661be9d

Please sign in to comment.