mirror of
https://github.com/liriliri/eruda.git
synced 2026-02-02 09:49:00 +08:00
feat(resources): copy storage, cookie
This commit is contained in:
@@ -2,6 +2,7 @@ import map from 'licia/map'
|
||||
import trim from 'licia/trim'
|
||||
import isNull from 'licia/isNull'
|
||||
import each from 'licia/each'
|
||||
import copy from 'licia/copy'
|
||||
import LunaModal from 'luna-modal'
|
||||
import LunaDataGrid from 'luna-data-grid'
|
||||
import { setState, getState } from './util'
|
||||
@@ -72,6 +73,9 @@ export default class Cookie {
|
||||
<div class="btn show-detail btn-disabled">
|
||||
<span class="icon icon-eye"></span>
|
||||
</div>
|
||||
<div class="btn copy-cookie btn-disabled">
|
||||
<span class="icon icon-copy"></span>
|
||||
</div>
|
||||
<div class="btn delete-cookie btn-disabled">
|
||||
<span class="icon icon-delete"></span>
|
||||
</div>
|
||||
@@ -93,14 +97,17 @@ export default class Cookie {
|
||||
const $container = this._$container
|
||||
const $showDetail = $container.find(c('.show-detail'))
|
||||
const $deleteCookie = $container.find(c('.delete-cookie'))
|
||||
const $copyCookie = $container.find(c('.copy-cookie'))
|
||||
const btnDisabled = c('btn-disabled')
|
||||
|
||||
$showDetail.addClass(btnDisabled)
|
||||
$deleteCookie.addClass(btnDisabled)
|
||||
$copyCookie.addClass(btnDisabled)
|
||||
|
||||
if (this._selectedItem) {
|
||||
$showDetail.rmClass(btnDisabled)
|
||||
$deleteCookie.rmClass(btnDisabled)
|
||||
$copyCookie.rmClass(btnDisabled)
|
||||
}
|
||||
}
|
||||
_getVal(key) {
|
||||
@@ -144,6 +151,11 @@ export default class Cookie {
|
||||
showSources('raw', val)
|
||||
}
|
||||
})
|
||||
.on('click', c('.copy-cookie'), () => {
|
||||
const key = this._selectedItem
|
||||
copy(this._getVal(key))
|
||||
devtools.notify('Copied')
|
||||
})
|
||||
.on('click', c('.filter'), () => {
|
||||
LunaModal.prompt('Filter').then((filter) => {
|
||||
if (isNull(filter)) return
|
||||
|
||||
@@ -6,6 +6,7 @@ import LunaModal from 'luna-modal'
|
||||
import LunaDataGrid from 'luna-data-grid'
|
||||
import isNull from 'licia/isNull'
|
||||
import trim from 'licia/trim'
|
||||
import copy from 'licia/copy'
|
||||
import { safeStorage, classPrefix as c } from '../lib/util'
|
||||
|
||||
export default class Storage {
|
||||
@@ -87,14 +88,17 @@ export default class Storage {
|
||||
const $container = this._$container
|
||||
const $showDetail = $container.find(c('.show-detail'))
|
||||
const $deleteStorage = $container.find(c('.delete-storage'))
|
||||
const $copyStorage = $container.find(c('.copy-storage'))
|
||||
const btnDisabled = c('btn-disabled')
|
||||
|
||||
$showDetail.addClass(btnDisabled)
|
||||
$deleteStorage.addClass(btnDisabled)
|
||||
$copyStorage.addClass(btnDisabled)
|
||||
|
||||
if (this._selectedItem) {
|
||||
$showDetail.rmClass(btnDisabled)
|
||||
$deleteStorage.rmClass(btnDisabled)
|
||||
$copyStorage.rmClass(btnDisabled)
|
||||
}
|
||||
}
|
||||
_initTpl() {
|
||||
@@ -110,6 +114,9 @@ export default class Storage {
|
||||
<div class="btn show-detail btn-disabled">
|
||||
<span class="icon icon-eye"></span>
|
||||
</div>
|
||||
<div class="btn copy-storage btn-disabled">
|
||||
<span class="icon icon-copy"></span>
|
||||
</div>
|
||||
<div class="btn delete-storage btn-disabled">
|
||||
<span class="icon icon-delete"></span>
|
||||
</div>
|
||||
@@ -127,6 +134,11 @@ export default class Storage {
|
||||
this._$dataGrid = $container.find(c('.data-grid'))
|
||||
this._$filterText = $container.find(c('.filter-text'))
|
||||
}
|
||||
_getVal(key) {
|
||||
return this._type === 'local'
|
||||
? localStorage.getItem(key)
|
||||
: sessionStorage.getItem(key)
|
||||
}
|
||||
_bindEvent() {
|
||||
const type = this._type
|
||||
const devtools = this._devtools
|
||||
@@ -148,11 +160,7 @@ export default class Storage {
|
||||
})
|
||||
.on('click', c('.show-detail'), () => {
|
||||
const key = this._selectedItem
|
||||
|
||||
const val =
|
||||
type === 'local'
|
||||
? localStorage.getItem(key)
|
||||
: sessionStorage.getItem(key)
|
||||
const val = this._getVal(key)
|
||||
|
||||
try {
|
||||
showSources('object', JSON.parse(val))
|
||||
@@ -160,6 +168,11 @@ export default class Storage {
|
||||
showSources('raw', val)
|
||||
}
|
||||
})
|
||||
.on('click', c('.copy-storage'), () => {
|
||||
const key = this._selectedItem
|
||||
copy(this._getVal(key))
|
||||
devtools.notify('Copied')
|
||||
})
|
||||
.on('click', c('.filter'), () => {
|
||||
LunaModal.prompt('Filter').then((filter) => {
|
||||
if (isNull(filter)) return
|
||||
|
||||
Reference in New Issue
Block a user