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

Inline file view #3

Open
wants to merge 6 commits into
base: main
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
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,15 @@
# hardware-github-viewer
Chrome extension for viewing Kicad and FreeCAD files in github

## Dependencies
In Scripts you'll find a couple of dependencies:

* `webcomponents-bundle.js`
This is from the WebComponents polyfill, because Chrome Extensions don't support WebComponents.
More info here:
https://github.com/webcomponents/polyfills?tab=readme-ov-file#packages

* `kiCanvas.js`
This renders the Schematic and PCB files in a Canvas.
More info here:
https://github.com/theacodes/kicanvas
50 changes: 27 additions & 23 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -1,24 +1,28 @@
{
"manifest_version": 3,
"name": "GitHub Hardware Viewer",
"description": "Tool for viewing hardware design files on Github",
"version": "1.1",
"action": {
"default_popup": "hello.html",
"default_icon": "opulo.png"
},
"content_scripts": [
{
"js": ["scripts/content.js"],
"matches": [
"https://github.com/*"
]
}
],
"web_accessible_resources": [
{
"resources": [ "opulo.png" ],
"matches": [ "https://github.com/*" ]
}
]
}
"manifest_version": 3,
"name": "GitHub Hardware Viewer",
"description": "Tool for viewing hardware design files on Github",
"version": "1.1",
"action": {
"default_popup": "hello.html",
"default_icon": "opulo.png"
},
"content_scripts": [
{
"js": [
"scripts/webcomponents-bundle.js",
"scripts/content.js",
"scripts/kicanvas.js",
"scripts/viewer.js"
],
"run_at": "document_idle",
"matches": ["https://github.com/*"]
}
],
"web_accessible_resources": [
{
"resources": ["opulo.png", "scripts/kicanvas.js"],
"matches": ["https://github.com/*"]
}
]
}
26 changes: 26 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"devDependencies": {
"@webcomponents/webcomponentsjs": "^2.8.0"
}
}
1,895 changes: 1,895 additions & 0 deletions scripts/kicanvas.js

Large diffs are not rendered by default.

39 changes: 39 additions & 0 deletions scripts/viewer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@


function displayKiCanvas() {
if(document.location.href.match(/blob.+?(kicad_pcb|kicad_sch|kicad_pro)/) !== null) {

setTimeout(()=>{
const b = document.querySelector(`[data-target="react-app.reactRoot"]>div>div>div>div>div:last-child>div>div>div:last-child>div:last-child>div.container>div:last-child`)

ke = document.createElement(`kicanvas-embed`);
ke.src=document.querySelector(`.react-blob-header-edit-and-raw-actions>div>a`).href;
console.log(`Src File: ${ke.src}`);
ke.setAttribute('controls', 'full');
ke.style.zIndex = "10000";
ke.style.position = "relative";
ke.style.top = "0px";
ke.style.left = "0px";
b.prepend(ke);
},500);
}
}

//When the URL changes, we want to rerun displayKiCanvas.
let lastUrl = location.href;
new MutationObserver(() => {
const url = location.href;
if (url !== lastUrl) {
lastUrl = url;
onUrlChange();
}
}).observe(document, {subtree: true, childList: true});

function onUrlChange() {
//Remove any existing kicanvas.
document.querySelectorAll("kicanvas-embed").forEach(e=>e.remove());

displayKiCanvas();
}

displayKiCanvas();
Loading