Skip to content

Commit

Permalink
Format the code
Browse files Browse the repository at this point in the history
  • Loading branch information
hsluoyz committed Mar 12, 2024
1 parent 18ee0db commit 98f229c
Show file tree
Hide file tree
Showing 7 changed files with 113 additions and 93 deletions.
26 changes: 21 additions & 5 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,14 @@ module.exports = {
"space-in-parens": ["error", "never"],
"object-curly-spacing": ["error", "never"],
"array-bracket-spacing": ["error", "never"],
"comma-spacing": ["error", {before: false, after: true}],
"arrow-spacing": ["error", {before: true, after: true}],
"comma-spacing": ["error", {
before: false,
after: true
}],
"arrow-spacing": ["error", {
before: true,
after: true
}],
"space-before-blocks": ["error", "always"],
"spaced-comment": ["error", "always"],
"block-spacing": ["error", "never"],
Expand All @@ -43,11 +49,21 @@ module.exports = {
],
"no-multiple-empty-lines": [
"error",
{max: 1, maxBOF: 0, maxEOF: 0},
{
max: 1,
maxBOF: 0,
maxEOF: 0
},
],
"space-unary-ops": ["error", {words: true, nonwords: false}],
"space-unary-ops": ["error", {
words: true,
nonwords: false
}],
"space-infix-ops": "error",
"key-spacing": ["error", {beforeColon: false, afterColon: true}],
"key-spacing": ["error", {
beforeColon: false,
afterColon: true
}],
"comma-style": ["error", "last"],
"comma-dangle": [
"error",
Expand Down
18 changes: 9 additions & 9 deletions .releaserc.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"debug": true,
"branches": "master",
"plugins": [
"@semantic-release/commit-analyzer",
"@semantic-release/release-notes-generator",
"@semantic-release/npm",
"@semantic-release/github"
]
}
"debug": true,
"branches": "master",
"plugins": [
"@semantic-release/commit-analyzer",
"@semantic-release/release-notes-generator",
"@semantic-release/npm",
"@semantic-release/github"
]
}
75 changes: 39 additions & 36 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -1,40 +1,43 @@
{
"name": "Casdoor",
"description": "The Casdoor extension can help browser users automatically log into applications protected by Casdoor single-sign-on (SSO) system.",
"version": "1.0.0",
"manifest_version": 3,
"permissions": ["storage", "identity"],
"action": {
"default_popup": "/src/popup.html",
"default_icon": {
"16": "/images/icon16.png",
"32": "/images/icon32.png",
"48": "/images/icon48.png",
"128": "/images/icon128.png"
}
},
"icons": {
"16": "/images/icon16.png",
"32": "/images/icon32.png",
"48": "/images/icon48.png",
"128": "/images/icon128.png"
},
"content_scripts": [
{
"matches": [
"https://*/*",
"http://*/*"
],
"js": [
"/src/content-script.js",
"/src/sdk.js",
"/src/oauth.js",
"/src/config.js"
]
}
],
"host_permissions": [
"name": "Casdoor",
"description": "The Casdoor extension can help browser users automatically log into applications protected by Casdoor single-sign-on (SSO) system.",
"version": "1.0.0",
"manifest_version": 3,
"permissions": [
"storage",
"identity"
],
"action": {
"default_popup": "/src/popup.html",
"default_icon": {
"16": "/images/icon16.png",
"32": "/images/icon32.png",
"48": "/images/icon48.png",
"128": "/images/icon128.png"
}
},
"icons": {
"16": "/images/icon16.png",
"32": "/images/icon32.png",
"48": "/images/icon48.png",
"128": "/images/icon128.png"
},
"content_scripts": [
{
"matches": [
"https://*/*",
"http://*/*"
]
],
"js": [
"/src/content-script.js",
"/src/sdk.js",
"/src/oauth.js",
"/src/config.js"
]
}
],
"host_permissions": [
"https://*/*",
"http://*/*"
]
}
22 changes: 11 additions & 11 deletions src/oauth.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ function login() {
.getUserProfile(accessToken)
.then((userProfile) => displayUserProfile(userProfile));
});
setInputDisabledState(true, "endpoint", "applicationName")
setInputDisabledState(true, "endpoint", "applicationName");
} else {
alert("Login failed!");
}
Expand All @@ -50,7 +50,7 @@ function login() {
// eslint-disable-next-line no-unused-vars
function logout() {
chrome.storage.sync.set({accessToken: ""}, () => clearUserProfile());
setInputDisabledState(false, "endpoint", "applicationName")
setInputDisabledState(false, "endpoint", "applicationName");
}

function displayUserProfile(userProfile) {
Expand All @@ -66,13 +66,13 @@ function clearUserProfile() {
document.getElementById("loginOrLogout").innerText = "Login";
}

function setInputDisabledState(disabledState, ...elementIds) {
elementIds.forEach(elementId => {
const inputElement = document.getElementById(elementId);
if (inputElement) {
inputElement.disabled = disabledState;
} else {
console.warn(`No element found with ID: ${elementId}`);
}
});
function setInputDisabledState(disabledState, ...elementIds) {
elementIds.forEach(elementId => {
const inputElement = document.getElementById(elementId);
if (inputElement) {
inputElement.disabled = disabledState;
} else {
console.warn(`No element found with ID: ${elementId}`);
}
});
}
58 changes: 29 additions & 29 deletions src/popup.html
Original file line number Diff line number Diff line change
@@ -1,34 +1,34 @@
<!DOCTYPE html>
<html>
<head>
<head>
<link rel="stylesheet" href="popup.css">
</head>
<body>
<div class="background">
<h1 class="title" id="title">Casdoor</h1>
<div id="user"></div>
<div class="item">
endpoint:
<input class="input" id="endpoint" name="endpoint" placeholder="your casdoor server url"/>
</div>
<div class="item">
applicationName:
<input class="input" id="applicationName" name="applicationName" placeholder="your application name"/>
</div>
<div class="item">
Enable auto login:
<label class="switch">
<input type="checkbox" id="enableAutoLogin">
<span class="slider"></span>
</label>
</div>
<div class="control">
<button class="primary" id="loginOrLogout">Login</button>
</div>
</head>
<body>
<div class="background">
<h1 class="title" id="title">Casdoor</h1>
<div id="user"></div>
<div class="item">
endpoint:
<input class="input" id="endpoint" name="endpoint" placeholder="your casdoor server url"/>
</div>
<script src="config.js"></script>
<script src="sdk.js"></script>
<script src="oauth.js"></script>
<script src="popup.js"></script>
</body>
<div class="item">
applicationName:
<input class="input" id="applicationName" name="applicationName" placeholder="your application name"/>
</div>
<div class="item">
Enable auto login:
<label class="switch">
<input type="checkbox" id="enableAutoLogin">
<span class="slider"></span>
</label>
</div>
<div class="control">
<button class="primary" id="loginOrLogout">Login</button>
</div>
</div>
<script src="config.js"></script>
<script src="sdk.js"></script>
<script src="oauth.js"></script>
<script src="popup.js"></script>
</body>
</html>
2 changes: 1 addition & 1 deletion src/popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ document.addEventListener("DOMContentLoaded", function() {
const managedAccounts = account.data.managedAccounts;
chrome.storage.sync.set({managedAccounts});
});
setInputDisabledState(true, "endpoint", "applicationName")
setInputDisabledState(true, "endpoint", "applicationName");
} else {
clearUserProfile();
}
Expand Down
5 changes: 3 additions & 2 deletions src/sdk.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
// limitations under the License.

/* eslint-disable no-undef */

// eslint-disable-next-line no-unused-vars
class Sdk {
constructor(config) {
Expand All @@ -38,8 +39,8 @@ class Sdk {

getAccessTokenFromRedirectUrl(redirectUrl) {
if (redirectUrl) {
const accessTokenMatch = redirectUrl.match(/#access_token=([^&]*)/);
const accessToken = accessTokenMatch ? accessTokenMatch[1] : "";
const accessTokenMatch = redirectUrl.match(/#access_token=([^&]*)/);
const accessToken = accessTokenMatch ? accessTokenMatch[1] : "";
return accessToken;
}
return "";
Expand Down

0 comments on commit 98f229c

Please sign in to comment.