Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
</a>
</p>

This is a static [Next.js](https://nextjs.org/) site providing a searchable library of all the algorithms in [The Algorithms](https://github.com/TheAlgorithms). All the data about the algorithms gets scraped directly from the git repositories.
This is a static [Next.js](https://nextjs.org/) site providing a searchable library of all the algorithms in [The Algorithms](https://github.com/TheAlgorithms). All the data about the algorithms gets scraped directly from the git repositories. Unlock the world of algorithms with a single click and explore the magic of code in action.

## Translating the website

Expand Down
20 changes: 19 additions & 1 deletion components/codePreview/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,16 @@ export default function CodePreview({ algorithm }: { algorithm: Algorithm }) {
const theme = useTheme();
const fabRef = useRef();
const [mobileMoreMenuOpen, setMobileMoreMenuOpen] = useState(false);
const copyCode = () =>
{
var str = document.querySelector(".style_pre__k555n").textContent;
const el = document.createElement('textarea');
el.value = str;
document.body.appendChild(el);
el.select();
document.execCommand('copy');
document.body.removeChild(el);
};

return (
<div className={`${classes.container}`}>
Expand Down Expand Up @@ -116,7 +126,7 @@ export default function CodePreview({ algorithm }: { algorithm: Algorithm }) {
href={`/playground?algorithm=${algorithm.slug}&language=${selectedLanguague}`}
passHref
>
<Button
<Button
color="primary"
variant="contained"
className={classes.tryCode}
Expand All @@ -125,6 +135,14 @@ export default function CodePreview({ algorithm }: { algorithm: Algorithm }) {
{t("playgroundTryCode")}
</Button>
</NextLink>
<Button
color="primary"
variant="contained"
className={classes.tryCode}
onClick = {() => copyCode()}
>
{("Copy Code")}
</Button>
</div>
</>
)}
Expand Down
1 change: 1 addition & 0 deletions styles/globals.css
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ body {
}

.dark .section a {
margin-right: 6px;
color: #00bcb4;
}

Expand Down