mirror of
https://github.com/Tygs/0bin.git
synced 2023-08-10 21:13:00 +03:00
Reader mode param in URL
This commit is contained in:
parent
d133494e9d
commit
6bf5333b14
@ -101,9 +101,9 @@ class Paste(object):
|
|||||||
expiration = datetime.strptime(expiration, "%Y-%m-%d %H:%M:%S.%f")
|
expiration = datetime.strptime(expiration, "%Y-%m-%d %H:%M:%S.%f")
|
||||||
|
|
||||||
except StopIteration:
|
except StopIteration:
|
||||||
raise TypeError(to_ascii("File %s is malformed" % path))
|
raise TypeError("File %s is malformed" % path)
|
||||||
except (IOError, OSError):
|
except (IOError, OSError):
|
||||||
raise ValueError(to_ascii("Can not open paste from file %s" % path))
|
raise ValueError("Can not open paste from file %s" % path)
|
||||||
|
|
||||||
return Paste(uuid=uuid, expiration=expiration, content=content)
|
return Paste(uuid=uuid, expiration=expiration, content=content)
|
||||||
|
|
||||||
@ -230,10 +230,13 @@ class Paste(object):
|
|||||||
os.remove(self.path)
|
os.remove(self.path)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def iter_all(cls):
|
def iter_all(cls, on_error=lambda e: e):
|
||||||
for p in settings.PASTE_FILES_ROOT.rglob("*"):
|
for p in settings.PASTE_FILES_ROOT.rglob("*"):
|
||||||
if p.is_file() and "counter" not in str(p):
|
if p.is_file() and "counter" not in str(p):
|
||||||
|
try:
|
||||||
yield Paste.load_from_file(p)
|
yield Paste.load_from_file(p)
|
||||||
|
except (TypeError, ValueError) as e:
|
||||||
|
on_error(e)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def has_expired(self):
|
def has_expired(self):
|
||||||
|
@ -45,6 +45,8 @@ const app = new Vue({
|
|||||||
|
|
||||||
clipboard: !!(isSecureContext && navigator.clipboard && navigator.clipboard.writeText),
|
clipboard: !!(isSecureContext && navigator.clipboard && navigator.clipboard.writeText),
|
||||||
|
|
||||||
|
URLSearchParams: !!window.URLSearchParams,
|
||||||
|
|
||||||
localStorage: (function () {
|
localStorage: (function () {
|
||||||
var val = !!(localStorage);
|
var val = !!(localStorage);
|
||||||
document.querySelector('html').classList.add((val ? '' : 'no-') + 'local-storage');
|
document.querySelector('html').classList.add((val ? '' : 'no-') + 'local-storage');
|
||||||
@ -68,13 +70,21 @@ const app = new Vue({
|
|||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
|
||||||
// handleDownload: function () {
|
|
||||||
// this.$refs.downloadLink.dispatchEvent(new Event("click"));
|
|
||||||
// },
|
|
||||||
|
|
||||||
toggleReaderMode: function () {
|
toggleReaderMode: function () {
|
||||||
|
debugger;
|
||||||
if (!this.readerMode) {
|
if (!this.readerMode) {
|
||||||
this.messages = [];
|
this.messages = [];
|
||||||
|
if (this.support.URLSearchParams) {
|
||||||
|
var searchParams = new URLSearchParams(window.location.search)
|
||||||
|
searchParams.set('readerMode', 1);
|
||||||
|
window.location.search = searchParams.toString();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (this.support.URLSearchParams) {
|
||||||
|
var searchParams = new URLSearchParams(window.location.search);
|
||||||
|
searchParams.delete('readerMode');
|
||||||
|
window.location.search = searchParams.toString();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.readerMode = !this.readerMode;
|
this.readerMode = !this.readerMode;
|
||||||
@ -391,6 +401,7 @@ window.zerobin = {
|
|||||||
doneCallback(content);
|
doneCallback(content);
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
debugger;
|
||||||
errorCallback(err);
|
errorCallback(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -738,6 +749,8 @@ if (content && key) {
|
|||||||
/* When done */
|
/* When done */
|
||||||
function (content) {
|
function (content) {
|
||||||
|
|
||||||
|
let readerMode = false;
|
||||||
|
|
||||||
if (content.indexOf('data:image') == 0) {
|
if (content.indexOf('data:image') == 0) {
|
||||||
// Display Image
|
// Display Image
|
||||||
|
|
||||||
@ -773,6 +786,10 @@ if (content && key) {
|
|||||||
url: "data:text/html;charset=UTF-8," + content
|
url: "data:text/html;charset=UTF-8," + content
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (app.support.URLSearchParams) {
|
||||||
|
readerMode = (new URLSearchParams(window.location.search)).get('readerMode');
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
bar.set('Code coloration...', '95%');
|
bar.set('Code coloration...', '95%');
|
||||||
|
|
||||||
@ -781,7 +798,7 @@ if (content && key) {
|
|||||||
|
|
||||||
/** Syntaxic coloration */
|
/** Syntaxic coloration */
|
||||||
|
|
||||||
if (zerobin.isCode(content) > 100) {
|
if (zerobin.isCode(content) > 100 && !readerMode) {
|
||||||
document.getElementById('paste-content').classList.add('linenums');
|
document.getElementById('paste-content').classList.add('linenums');
|
||||||
prettyPrint();
|
prettyPrint();
|
||||||
} else {
|
} else {
|
||||||
@ -805,6 +822,9 @@ if (content && key) {
|
|||||||
|
|
||||||
form.forEach((node) => node.disabled = false);
|
form.forEach((node) => node.disabled = false);
|
||||||
content = '';
|
content = '';
|
||||||
|
if (readerMode) {
|
||||||
|
app.toggleReaderMode()
|
||||||
|
}
|
||||||
|
|
||||||
}, 100);
|
}, 100);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user