Skip to content

Instantly share code, notes, and snippets.

@lv7777
Created January 7, 2016 03:06
Show Gist options
  • Select an option

  • Save lv7777/138e041591e521c5ff3d to your computer and use it in GitHub Desktop.

Select an option

Save lv7777/138e041591e521c5ff3d to your computer and use it in GitHub Desktop.
進捗を保存したい2で使用する。
// ==UserScript==
// @name 保存
// @namespace lv7777
// @description document.designmode="on"のhtmlを保存する(予定
// @include https://*
// @include http://*
// @version 1
// @grant none
// @require https://cdnjs.cloudflare.com/ajax/libs/dexie/1.2.0/Dexie.js
// ==/UserScript==
(function check(){
if(document.designMode=="on"){
console.log("ok");
autosave();
}else{
console.log("まだあわてるような時間じゃない");
setTimeout(check,10000);
}
})();
function autosave(){
console.log("in")
var src = document.getElementsByTagName("html")[0].innerHTML;
indexedDB(src);
setTimeout(autosave,10000);
}
function localstrage(data){
if(('localStorage' in window) && (window.localStorage !== null)) {
// ローカルストレージが使える
window.localStorage.setItem("backup",data);
console.log("保存しました");
} else {
// 使えない。。。
alert("!?")
}
}
function indexedDBsample(data){
/*
|---------------------------------------------
| Make a database connection
|---------------------------------------------
*/
var db = new Dexie('MyDatabase');
// Define a schema
db.version(1)
.stores({
friends: 'name, age'
});
// Open the database
db.open()
.catch(function(error){
alert('Uh oh : ' + error);
});
// or make a new one
db.friends
.add({
name: 'Camilla',
age: 25
});
db.friends
.add({
name: 'html',
age: src
});
alert("ok!");
}
function indexedDB(data){
alert("ok?")
var db=new Dexie("backupDB");
var dbStructure={
backup:"length,data,date"
}
//storesがtableか。だったら tableにしろよな
db.version(1).stores(dbStructure);
db.open().catch(function(error){
alert('Uh oh : ' + error);
});
db.backup.add(dbAddObject);
var dbAddObject={
length:data.length,
data,//es6
date:new Date()
}
console.log(new Date())
}
//firefoxでは実行できないのでfirefoxは糞
function blobfile(data){
var text = "テキストデータ";
var blob = new Blob([text], {type: "text/plain"}); // バイナリデータを作ります。
// IEか他ブラウザかの判定
if(window.navigator.msSaveBlob)
{
// IEなら独自関数を使います。
window.navigator.msSaveBlob(blob, "ファイル名.txt");
} else {
// それ以外はaタグを利用してイベントを発火させます
var a = document.createElement("a");
a.href = URL.createObjectURL(blob);
//alert(a.href)
a.target = '_';
a.download = 'ファイル名.txt';
a.click();
//alert(a.href)
}
}
function fileSystemAPI(data){
}
function xpcom(data){
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment