Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
R
retypos-webclient
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
eterfund
retypos-webclient
Commits
20ac46e3
Commit
20ac46e3
authored
Jul 13, 2017
by
George Popoff
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add typos correction in browser
parent
d6d3d0d3
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
80 additions
and
1 deletion
+80
-1
etersoft_typos.js
etersoft_typos.js
+75
-1
stylesheet.css
stylesheet.css
+5
-0
No files found.
etersoft_typos.js
View file @
20ac46e3
...
...
@@ -31,6 +31,9 @@ ETYPOS.prototype = {
needConstructPanel
:
true
,
element
:
null
,
// Idar
pageId
:
0
,
/* Переменные для перетаскивания */
isDragged
:
false
,
...
...
@@ -248,7 +251,11 @@ ETYPOS.prototype = {
this
.
request
=
new
(
window
.
XDomainRequest
||
window
.
XMLHttpRequest
);
this
.
userdata
[
'old_browser'
]
=
(
this
.
request
.
withCredentials
==
undefined
)
?
1
:
0
;
this
.
pageId
=
this
.
_getQueryVariable
(
"idar"
);
// Исправляем ошибки, которые исправил пользователь
this
.
fixTypos
();
},
clearSelectedText
:
function
()
{
...
...
@@ -432,6 +439,11 @@ ETYPOS.prototype = {
if
(
response
[
'success'
]
&&
response
[
'message'
])
{
if
(
response
[
'success'
]
==
'true'
)
{
var
success
=
'success'
;
// Устанавливаем исправленный вариант в localStorage
this_object
.
storeTypo
(
form_data
.
get
(
"text"
),
form_data
.
get
(
"comment"
));
this_object
.
fixTypos
();
}
else
{
var
success
=
'error'
;
}
...
...
@@ -496,6 +508,68 @@ ETYPOS.prototype = {
return
true
;
}
return
false
;
},
storeTypo
:
function
(
typo
,
correct
)
{
var
corrected
;
if
(
!
(
corrected
=
localStorage
.
getItem
(
"typos.corrected"
))
)
{
corrected
=
{};
}
else
{
corrected
=
JSON
.
parse
(
corrected
);
}
// Исправления для текущей новости
var
pageFixes
=
corrected
[
this
.
pageId
];
if
(
!
pageFixes
)
{
corrected
[
this
.
pageId
]
=
[];
}
corrected
[
this
.
pageId
].
push
({
text
:
typo
,
correct
:
correct
});
localStorage
.
setItem
(
"typos.corrected"
,
JSON
.
stringify
(
corrected
));
},
fixTypos
:
function
()
{
var
corrected
;
if
(
!
(
corrected
=
localStorage
.
getItem
(
"typos.corrected"
))
)
{
return
;
}
corrected
=
JSON
.
parse
(
corrected
);
// Смотрим исправления на этой странице
var
pageFixes
=
corrected
[
this
.
pageId
];
if
(
!
pageFixes
)
{
return
;
}
// Вторая таблица - контент
var
content
=
document
.
getElementsByClassName
(
"post"
)[
0
];
var
pageText
=
content
.
innerHTML
;
pageFixes
.
forEach
(
function
(
typo
)
{
var
text
=
typo
.
text
;
var
correct
=
typo
.
correct
;
pageText
=
pageText
.
replace
(
text
,
"<span class='corrected-text'>"
+
correct
+
"</span>"
);
});
content
.
innerHTML
=
pageText
;
// if ( !this.needConstructPanel ) {
// this._handleEvents();
// }
},
// Получает параметр из строки запроса
_getQueryVariable
:
function
(
variable
)
{
var
query
=
window
.
location
.
search
.
substring
(
1
);
var
vars
=
query
.
split
(
"&"
);
for
(
var
i
=
0
;
i
<
vars
.
length
;
i
++
)
{
var
pair
=
vars
[
i
].
split
(
"="
);
if
(
pair
[
0
]
===
variable
)
{
return
pair
[
1
];
}
}
return
0
;
}
};
stylesheet.css
View file @
20ac46e3
...
...
@@ -98,4 +98,8 @@
display
:
block
;
margin
:
0
auto
;
margin-top
:
10px
;
}
.corrected-text
{
background-color
:
rgba
(
0
,
250
,
0
,
0.25
);
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment