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

Support for gists #20

Open
Hexer10 opened this issue Mar 23, 2020 · 1 comment · May be fixed by #21
Open

Support for gists #20

Hexer10 opened this issue Mar 23, 2020 · 1 comment · May be fixed by #21
Assignees

Comments

@Hexer10
Copy link

Hexer10 commented Mar 23, 2020

I'd like to see a new feature that will allow us to share links such as https://spider.limetech.io/<gist id>, and the content of the gist would be inserted in the spider page.
In this way a link could be shared and the code could be compiled right away.
(I got the idea of this from https://dartpad.dev which does the same thing.)

If you think this is doable, I could send a pull request implementing the gists api, I'd just need some help on how to handle the routing.

@asherkin
Copy link
Owner

This is something I'd really like! I'd been waiting until giving Spider a complete overhaul, but if you'd like to add it into to the current code base I would gladly accept the PR. I had a look at the Gist API for saving a few weeks back and was slightly saddened to learn that GitHub doesn't have an implicit grant flow that SPAs can use safely.

Spider already supports a rather hacky and experimental version of this loading from AlliedModders forum attachments: https://spider.limetech.io/#180045 (Probably broken at the time of reading this due to the AM maintenance.)

The code for that can be found here:

spider/src/js/spider.js

Lines 327 to 374 in c24afa0

if (location.hash.match(/^#\d+$/)) {
for (var i = localStorage.length - 1; i >= 0; --i) {
var key = localStorage.key(i);
if (key.match(/^\//)) {
delete localStorage[key];
}
}
template = 'Loading...';
compileButton.disabled = true;
var xhr = new XMLHttpRequest();
xhr.onload = function() {
var type = this.getResponseHeader('Content-Type');
if (type == 'application/json') {
input.setValue(JSON.parse(this.responseText).error, -1);
return;
}
input.setValue(this.responseText, -1);
localStorage['input-file'] = this.responseText;
var filename = this.getResponseHeader('Content-Disposition');
if (filename) {
filename = filename.match(/filename="([^"]*)"/);
if (filename) {
filename = filename[1];
if (filename.match(/\.sp$/)) {
spcompSetup();
outputFile = filename.replace(/\.sp$/, '.smx');
compile();
} else if (filename.match(/\.sma$/)) {
amxxpcSetup();
outputFile = filename.replace(/\.sma$/, '.amxx');
compile();
}
}
}
compileButton.disabled = false;
}
xhr.open('GET', 'https://users.alliedmods.net/~asherkin/attachment.php?id=' + location.hash.slice(1), true);
xhr.send();
}

Probably best to be a little more future-proof and use #gist/<id>. It's also missing handling of the hashchange event.

@Hexer10 Hexer10 linked a pull request Mar 24, 2020 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants