Add basic file link functoin
Signed-off-by: Justin Georgi <justin.georgi@gmail.com>
This commit is contained in:
@@ -3,7 +3,7 @@
|
|||||||
"author": "Justin Georgi",
|
"author": "Justin Georgi",
|
||||||
"url": "https://gitea.azgeorgis.net/jgeorgi/mwModelViewer",
|
"url": "https://gitea.azgeorgis.net/jgeorgi/mwModelViewer",
|
||||||
"description": "This extension allows .glb and .gltf files to be added, displayed, and annotated in MediaWiki",
|
"description": "This extension allows .glb and .gltf files to be added, displayed, and annotated in MediaWiki",
|
||||||
"version": "0.0.1",
|
"version": "0.0.3",
|
||||||
"license-name": "MIT",
|
"license-name": "MIT",
|
||||||
"type": "media",
|
"type": "media",
|
||||||
"manifest_version": 2,
|
"manifest_version": 2,
|
||||||
@@ -26,6 +26,10 @@
|
|||||||
],
|
],
|
||||||
"packageFiles": [
|
"packageFiles": [
|
||||||
"glmv.js"
|
"glmv.js"
|
||||||
|
],
|
||||||
|
"dependencies": [
|
||||||
|
"mediawiki.util",
|
||||||
|
"mediawiki.api"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1 +1,47 @@
|
|||||||
console.log('GLMV JS loaded!')
|
console.log('GLMV JS loaded!')
|
||||||
|
|
||||||
|
let modelLoad = document.createElement('script')
|
||||||
|
modelLoad.setAttribute('type','module')
|
||||||
|
modelLoad.setAttribute('src','https://ajax.googleapis.com/ajax/libs/model-viewer/3.5.0/model-viewer.min.js')
|
||||||
|
let headElem = document.getElementsByTagName('head')[0]
|
||||||
|
headElem.appendChild(modelLoad)
|
||||||
|
let urlProm
|
||||||
|
|
||||||
|
let glbElems = document.querySelectorAll('.mw-body-content [href$=".glb"][title$=".glb"')
|
||||||
|
if (glbElems.length > 0) {
|
||||||
|
[...glbElems].forEach(ge => {
|
||||||
|
console.log(ge)
|
||||||
|
let modelRef = ge.href
|
||||||
|
if (modelRef.indexOf('File:') >= 0) {
|
||||||
|
console.log(`Getting true url of ${ge.title}`)
|
||||||
|
urlProm = getImageUrl(ge.title)
|
||||||
|
} else {
|
||||||
|
urlProm = Promise.resolve(() => {
|
||||||
|
return modelRef
|
||||||
|
})
|
||||||
|
}
|
||||||
|
Promise.all([urlProm]).then((imageUrl) => {
|
||||||
|
let newModel = document.createElement('model-viewer')
|
||||||
|
newModel.src = imageUrl
|
||||||
|
newModel.toggleAttribute('camera-controls')
|
||||||
|
newModel.toggleAttribute('ar')
|
||||||
|
ge.parentElement.replaceChild(newModel, ge)
|
||||||
|
console.log(`Replacing ${ge}...`)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
async function getImageUrl(imageTitle) {
|
||||||
|
if (!imageTitle || typeof imageTitle != 'string') return false
|
||||||
|
console.log('Making api call...')
|
||||||
|
const mwApi = new mw.Api
|
||||||
|
let apiResp = await mwApi.get({
|
||||||
|
"action": "query",
|
||||||
|
"format": "json",
|
||||||
|
"prop": "imageinfo",
|
||||||
|
"titles": imageTitle,
|
||||||
|
"iiprop": "url"
|
||||||
|
})
|
||||||
|
console.log(apiResp)
|
||||||
|
return apiResp.query.pages[Object.keys(apiResp.query.pages)[0]].imageinfo[0].url
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user